Dec 9, 2007
Me_ok_small Ilya Sabanin 1 post

Topic: Advanced Rails Recipes / Misinformation about using form_for with multiply models

Excerpt from Jay Field’s receipt “Simplifying Controllers With a Presenter”:

Lastly, using three different models doesn’t allow us to take advantage of Rails form_for method.

It’s not true. It’s possible to use form_for with multiply models using fields_for block:


<% form_for :user do |form| -%>
  <%= form.text_field :first_name %>
  <%= form.text_field :email %>

  <% fields_for :credit_card do |card_form| -%>
    <%= card_form.text_field :number %>
  <% end -%>
  <%= submit_tag %>
<% end -%>

More information in Rails 2.0.1 API.

1 post