Hi all My visitors can create party organisator profiles, and I want assign them as the creators (the field creator_id in the organisators table references a member in the members table). To do that I tried it with before_validation: def before_validation creator = Member.find 1 end Sadly, this does not work. The validation validates_presence_of :creator_id Still tells me, that creator needs a value. What''s wrong there? Somehow the attribute gets not filled with a value... I tried ith with self.creator = Member.find 1, and this would work, but surely is not clean, because creator is no static variable... Thanks for help. Josh -- Posted via http://www.ruby-forum.com/.
Joshua Muheim wrote:> Hi all > > My visitors can create party organisator profiles, and I want assign > them as the creators (the field creator_id in the organisators table > references a member in the members table). > To do that I tried it with before_validation: > > def before_validation > creator = Member.find 1 > end > > Sadly, this does not work. The validation > > validates_presence_of :creator_id > > Still tells me, that creator needs a value. > What''s wrong there? Somehow the attribute gets not filled with a > value... I tried ith with self.creator = Member.find 1, and this would > work, but surely is not clean, because creator is no static variable... > > Thanks for help. > Joshhi, maybe "@creator"? BTW could you point me to some info about using self, I thought you could use it like "this" in java, it''s simply pointing to the current object? -- Agnieszka -- Posted via http://www.ruby-forum.com/.
Reasonably Related Threads
- before before_validation callback
- before_create is after_validatation :on => :create , when it should be before_validation :on => :create
- unexpected behavior of before_validation
- Forms: handle foreign keys (AssociationTypeMismatch)
- [Sentry]-before_validation(model) not working for crypted-attribute?