SpringFlowers AutumnMoon
2009-May-26 04:24 UTC
how does form_for and validate_presence_of work hand in hand
when we have validate_presence_of :name in the model and then when we put in the create action that we re-render ''new'', then the form_for will populate the fields, and error_messages_for ''story'' will have the correct error message. this is really great, and and the same time, this looks like magic... i found that many books don''t explain how the magic occur. is it by some global variable? when the form_for is called... is it using the @story that came back from the @story.save, instead of the @story = Story.new from the new action? sometimes i feel that i am playing magic when using Ruby on Rails, except I don''t know how the magic happens... kind of like if I make the rabbit appear, but I don''t know how I did it. So I really want to know the inner workings of Rails. -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-May-26 07:30 UTC
Re: how does form_for and validate_presence_of work hand in hand
On May 26, 5:24 am, SpringFlowers AutumnMoon <rails-mailing- l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > this is really great, and and the same time, this looks like magic... i > found that many books don''t explain how the magic occur. is it by some > global variable? > > when the form_for is called... is it using the @story that came back > from the @story.save, instead of the @story = Story.new from the new > action?You render the new template, but you don''t run the new action again: the @story you display is indeed the one that you tried to save. Fred> > sometimes i feel that i am playing magic when using Ruby on Rails, > except I don''t know how the magic happens... kind of like if I make the > rabbit appear, but I don''t know how I did it. So I really want to know > the inner workings of Rails. > -- > Posted viahttp://www.ruby-forum.com/.