Hi, I’m puzzzled…
I have this model:
class UserCampaign < ActiveRecord::Base
attr_accessible :is_active, :user_id, :campaign_id
validates_presence_of :is_active, :user_id, :campaign_id
and have this observer:
class UserCampaignObserver < ActiveRecord::Observer
ucs = UserCampaign.find_all_by_user_id_and_is_active(user_campaign.user.id,true)
for uc in ucs do
uc.is_active = false
This is simple to guarantee that only one UserCampaign is active.
The problem is that when the observer runs, in uc.save!, the validation fails giving me an error saying that the attribute is_active is required…
If I remove is_required attribute from the list of validates_presence_of, everything goes fine.
Why it gives me that error saying that is_active is required when I have set it just before the save in the observer?