Text_field :first_name

HI ALL, i am new to rails and having a hard time understanding some

I have a Model called person and have this code fragment in my VIew
1 <%= form_for :person do |f| %>
2 First name: <%= f.text_field :first_name %>

3 <% end %>

does anybody know what :first_name means or what it does in line 2? In
my person model i have a first_name field… Is that an object or the
field itself im calling or what?

On 8 April 2011 05:18, Ad Ber [email protected] wrote:

field itself im calling or what?
The call:

f.text_field :first_name

does two things with the ‘first_name’ parameter.

First, it uses it to set the name of the form element:

<input name=“person[first_name]”…

When the form is submitted, this comes in as a parameter like this:

:person => {:first_name => ‘Bob’}

which you can use to easily create or update the person record.

Second, it can use the parameter to look up the existing value of the
person’s first_name (if it has one), and display that as the default
value in the form (i.e. if this was an update form, rather than a
create form). For instance, if you started with a @person object that
had the first_name of ‘Chad’, then you could get the following tag: