Problems with before_validation


#1

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


#2

Joshua M. 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.
Josh

hi,

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