Topic: how can insert different tables from single form.

Hi
i have a form for "Register" .
The functionality what i need is  ,when i submit the form.the post variables must insert into "Users" & "users_details" tables .
I can add this in a single table (users table).But i cant add details to second table.How can this possible.?Can any one help , i am new in ruby on rails.
My form is specified below
<h1>Register</h1>

<%= form_for :user do |f| %>
  <p>
      <%= f.label :FirstName%>:
    <%= f.text_field :FirstName %>
  </p>
  <p>
      <%= f.label :LastName%>:
    <%= f.text_field :LastName%>
  </p>
  <p>
    <%= f.label :UserName %>:
    <%= f.text_field :UserName %>
  </p>
  <p>
    <%= f.label :Email, "E-Mail" %>:
    <%= f.text_field :Email %>
  </p>
  <p>
    <%= f.label :Password %>:
    <%= f.password_field :Password  %>
  </p>
  <p>
      <%= f.label :City %>:
    <%= f.text_field :CityId %>
  <p>
      <%= f.submit "Register" %>
  </p>
<% end %>

Here firstname & lastname need to be stored in user details table & others must be in users table

pls help
rajesh

Last edited by saami (2012-04-19 04:15:50)

Re: how can insert different tables from single form.

Check out API documentation regarding "form_for", "fields_for" and nested attributes. You could also look at Railcasts about Nested Model Form for some hints.