KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to set a boolean field to false based on the value of another boolean field. I tried the following with an ActiveRecord model: before_save :reconcile_xvent def reconcile_xvent self.xvent_hood = false if !self.xvent_plenum? end But this doesn't work. Now, many of my unit tests fail with: ActiveRecord::RecordNotSaved: ActiveRecord::RecordNotSaved How can I set xvent_hood to be false if xvent_plenum is false? Update Here's what works (some of which comes from the comments/answers below): before_validation :reconcile_xvent def reconcile_xvent if self.xvent_hood? self.xvent_hood = false unless xvent_plenum? end end I couldn't figure out to make it work without the "if self.xvent_hood?" part....
Tags (comma-separated)
Save Edits
Cancel