On 24 February 2011 14:55, Bhasker H. [email protected]
wrote:
wrote:
After you click ‘save’ it goes off to some controller action.
def create
At that time the validates in the model user.rb gets triggered, am I correct
to say that. It validates the fields based on the code likevalidates :uun, :presence => true, length => { :maximum =>12}, :uniqueness
=> true
validates :uname, :presence => true, length => { :maximum => 64} etc…after this I use puts “the name is #{uname}”. This has problem.
I keep telling you, you cannot just put code after the validates line,
that line is executed only once, when the file is loaded, it sets up
the callback stuff so that the appropriate methods are called when you
call save.
But if I do the puts in “before_save :encryt_password”. Then I have no
errors.I just want to add some more fields before saving the record, that’s why it
is important for me.
In that case you probably want to use the before_save filter. That
will let you specify a method to be called before each save. You can
do the extra stuff there.
Colin