How can I iterate through an array of objects (all the same model) using fields_for ? The array contains objects created by the current_user.
I currently have:
<%= f.fields_for :descriptionsbyuser do |description_form| %>
<p class="fields">
<%= description_form.text_area :entry, :rows => 3 %>
<%= description_form.link_to_remove "Remove this description" %>
<%= description_form.hidden_field :user_id, :value => current_user.id %>
</p>
<% end %>
But I want to replace the :descriptionsbyuser with an array I created in my controller - @descriptionsFromCurrentUser
This is also inside Ryan Bate's "nested_form_for"
Any pointers would be greatly appreciated!
Adam
Docs for fields_for
clearly shows you the way of using arrays:
Or a collection to be used:
<%= form_for @person do |person_form| %> ... <%= person_form.fields_for :projects, @active_projects do |project_fields| %> Name: <%= project_fields.text_field :name %> <% end %> ... <% end %>
@active_projects
here is your array.