small medium large xlarge

Me_ok_pragsmall
09 Dec 2007, 11:49
Ilya Sabanin (1 post)

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

bq. 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 -%>

</code>

More information in “Rails 2.0.1 API”:http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000908.

Mike-120_pragsmall
10 Dec 2007, 14:03
Mike Clark (51 posts)

Thanks. You’re correct that it’s misleading. I’ll clarify it, and the book will also have a full recipe on fields_for in the next beta version.

In future, I’d appreciate it if you’d add comments such as these (errors, omissions, etc.) to the errata page so I can track them better.

You must be logged in to comment