Hi guys, this is a really stupid question but I have a deadline and I'm very nervous and I've tried everything. In fact it even worked for a second but I must have broken something.
I have a default featured item that I want to be overridden any time I try to feature another item. I had it give an error before but I don't want it to error, I just want it to set everything to false and this app to true.
I've tried everything, before save, after save/update named scopes, mapping each one to false and then saving, checking for whether the feature has changed...I think I have all the right parts but I can't put them together. Please please help :(
Maybe there's even a quick validation for this, I'm not sure
I can't elaborate with code because I've tried a million different things.
There is a boolean setting on an item that is called is_featured.
When you create the item, you can set it to be featured or not.
In the database, if other items are featured, these should be zeroed out, and the item that was just updated or created to be featured should be true.
I have tried this in the model with before/after/save/update and also the controler on create and update
Fine I will add some of my stupid code which Id on't know why doesn't work
In the controller:
if params[:app][:is_on_front_page] == true
App.all.map{|m|( m != @app ) ? m.is_on_front_page = true : m.is_on_front_page = false}
end
or
named_scope :is_on_front_page, :conditions => { :is_on_front_page => true }
after_update do
if self.is_on_front_page.changed? and App.is_on_front_page.count >= 1
App.all.map{|m| m.is_on_front_page = false;m.save}
end
is_on_front_page = true
save!
end
but it won't let me save or gets into an infinite loop or yells at me because of the named scope