HI ALL, i am new to rails and having a hard time understanding some
things..
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 %><br />
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?
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: