Hey,

Thank you Colin.

Finally I got it.  I was trying to use it like in 'C', just as a variable in
a class.  But finally I learnt that it does not work like that and I have to
use it only inside a method.  I defined my own method and did all the
required step in that, so my next step is also done.

Sorry, if I have created lot of trouble to many of you.  I am very new to
Ruby, Rails and Web app (hardly a month) and I am working by myself from
home.

Warm Regards,
Bhasker.

On Thu, Feb 24, 2011 at 9:39 PM, Colin Law <[email protected]> wrote:

> On 24 February 2011 14:55, Bhasker Harihara <[email protected]>
> wrote:
> >
> >
> >
> > On Thu, Feb 24, 2011 at 6:50 PM, Colin Law <[email protected]>
> wrote:
> >>
> >> On 24 February 2011 12:36, Bhasker Harihara <[email protected]
> >
> >> wrote:
> >> >
> >> >
> >> > On Thu, Feb 24, 2011 at 5:55 PM, Colin Law <[email protected]>
> >> > wrote:
> >> >>
> >> >> On 24 February 2011 12:09, Bhasker Harihara
> >> >> <[email protected]>
> >> >> wrote:
> >> >> > ...
> >> >> > Can you also expalin how validates get the values from the form_for
> >> >>
> >> >> It doesn't, your code does that and then calls save.  When you call
> >> >> save the validations get called at appropriate points around the save
> >> >> to check the data.
> >> >>
> >> >> Have a look at the Rails Guide 'ActiveRecord Validations and
> Callback'.
> >> >>
> >> >> Colin
> >> >>
> >> >> --
> >> >
> >> >
> >> > I click "sign up" -> form_for gets displayed -> I click "save" then in
> >> > user.rb validates takes place.  Am I correct to say this.
> >>
> >> After you click 'save' it goes off to some controller action.
> >> Somewhere in there it presumably calls @user.save
> >> @user.update_attributes or one of the other ways that a record gets
> >> saved.  It is at this point that the validations get called.
> >>
> >> Colin
> >>
> >> --
> >
> > Yes, you are correct, I understand that.  In my users_contoller.rb I
> have,
> >
> >  def create
> >     @user = User.new(params[:user])
> >     # Handle a successful save.
> >     if @user.save
> >         redirect_to @user
> >     else
> >       @title = "Sign up"
> >       render 'new'
> >     end
> >   end
> >
> > 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 like
> >
> > validates :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
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to