开发者

Difference between fields_for syntax

开发者 https://www.devze.com 2023-01-19 03:33 出处:网络
Is there any difference between: <%= event_form.fields_for :client, @client do |client| %> and <%= fields_for @event, :client, @client do |client| %>开发者_Python百科

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消