I have a model that includes a :current boolean. The idea is that there are many home pages that the admin is working on at any given time, but only one is current at a time. At the moment, I have enforced this with the following:
before_save :toggle_current
def toggle_current
if current?
Home.where(["current = ? & id != ?", true, self.id]).each do |home|
home.update_attribute(:current, false)
end
end
end
Which works, but feels like a heavy solution to a simple problem. I could add a set of radio buttons to the index view and set it that way, but does anyone else have any other suggestions?
Thanks in advance,
Walter
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment