Basic question about form_for

The form_for api docs have this example:

<% form_for :person, @person, :url => { :action => "update" } do |f| %>

Can someone explain the function of :person and @person? I guess that @person was set in the controller. But then what is :person? Why do I need both?

The form_for api docs have this example:

<% form_for :person, @person, :url => { :action => "update" } do |f| %>

Can someone explain the function of :person and @person? I guess that @person was set in the controller. But then what is :person? Why do I need both?

Try it and then view the source to see the result... using this example:

<% form_for :person, @person, :url => { :action => "update" } do |f| %>      First name: <%= f.text_field :first_name %>      Last name : <%= f.text_field :last_name %>      Biography : <%= f.text_area :biography %>      Admin? : <%= f.check_box :admin %> <% end %>

You'd end up with form names of:

person[first_name] person[last_name] person[biography] person[admin]

That takes care of :person. @person is what is used to populate those fields with default values....

-philip

Uh… Weird. I’ve been using

form_for :model_name, :url => {:action => :whatever} do |f| end

and it works fine. I don’t know how/why I started doing it this way but it does work. Does Edge Rails use form_for differently? Is @person designed so you could use a different model there? I’m genuinely puzzled by this.

RSL