Difference between fields_for syntax
Is there any difference between:
<%= event_form.fields_for :client, @client do |client| %>
and
<%= fields_for @event, :client, @client do |client| %>开发者_Python百科
The parent form looks like this:
<% form_for @event do |event_form| %>
As I read from the docs (http://bit.ly/bMTJ5B), the first version
<%= event_form.fields_for :client, @client do |client| %>
is used in conjunction with accepts_nested_attributes_for :client and the update / create actions consider the event -> client association.
The second example:
<%= fields_for :client, @client do |client| %>
is the more general case when you need to specify additional models in the same form (see 'Generic Examples' section in the link I provided above. I think the correct form though is to leave out the @event param.
精彩评论