ruby on rails - Rails4 : Referencing associated model in fields_for partial -
i broke out form fields associated model partial. want reference associated model in partial i'm not sure how that. @position
, @position_fields
both nil. see render ..., object: @something
not sure how reference current position
model pass in.
apps/views/events/_form.html.erb
<%= f.fields_for :positions |builder| %> <%= render 'position_fields', f: builder %> <% end %>
apps/views/events/_position_fields.html.erb
fields <%= @position.name %> <%= f.text_field :name %>
how reference associated model in fields_for
partial?
in apps/views/events/_position_fields.html.erb, can following:
fields <%= f.object.name %> <%= f.text_field :name %>
this because builder
has reference each of position object , passing builder local position_fields
partial name f
.
reading through doc useful: http://apidock.com/rails/actionview/helpers/formhelper/fields_for.
Comments
Post a Comment