Reputation: 7166
Is it possible to pass variable when using nested form with Simple form?
Like
<%= simple_nested_form_for(@foo) do |f| %>
...
<%= f.simple_fields_for :bar %>
<%= f.link_to_add :bar do %>
Add bar
<% end %>
<% end %>
I have tried
<%= f.simple_fields_for :bar, :locals => {:baz => 'baz'} %>
but it wont pick it up in the partial.
Partial: _bar.html.erb
<%= baz %>
Upvotes: 0
Views: 1097
Reputation: 41
I was looking for the same thing and never did see an answer anywhere, so I'm posting an example of what worked for me:
<%= f.simple_fields_for :answers do |answers| %>
<%= render 'answer_fields', { f: answers, question: @question } %>
<% end %>
Also, if you want to access the current object from the collection being rendered within the partial, use f.object within the partial.
Upvotes: 2
Reputation: 1793
To pass variables to partials, you use the :locals
option:
<%= render partial: "my_awesome_partial", locals: {variable: 5, baz: 'baz'} %>
Upvotes: 1