In a Rails 3.2 app I'm using Simple Form to create a complex form.
The form/ model accepts_nested_attributes_for
, and I need to get the index of child objects.
The models:
class Project
has_many :tasks
accepts_nested_attributes_for :tasks
end
class Task
belongs_to :project
end
The form
<%= simple_form_for @project do |f| %>
<%= f.simple_fields_for :tasks do |builder| %>
## I need to get the index of each object built via builder
<% end %>
<% end %>
How do I correctly get the index?
You can use this:
<%= simple_form_for @project do |f| %>
<%= f.simple_fields_for :tasks do |builder| %>
<%= builder.index %>
<% end %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With