Forum: Ruby on Rails how does form_for and validate_presence_of work hand in hand

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eb71c362ddeda80c2668d2575e97bc70?d=identicon&s=25 winter heat (winterheat)
on 2009-05-26 06:24
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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-26 09:31
(Received via mailing list)
On May 26, 5:24 am, SpringFlowers AutumnMoon <rails-mailing-
l...@andreas-s.net> 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
This topic is locked and can not be replied to.