I would appreciate your help regarding this:
I have 2 models, book and author, where Book has many Authors and Author belongs to Book
I have the code below which allows user to add multiple authors to book.
<% fields_for @book do |f| %>
<% f.fields_for :authors do |builder| %>
<%= render 'author_fields', :f => builder %>
<% end %>
<p><%= link_to_add_fields "Add Authors", f, :authors %></p>
<% end %>
_author_fields.html.erb
<%= f.text_field :author_name %>
When editing a book entry, I would like to access the author name in the ‘_author_fields’ partial and store it in a variable.
Something like: <%= author.author_name %> **this does not work
How do I do that?
Thanks for any suggestion
You can get author in the ‘author_fields’ form with the local f you are passing:
Then you can get the name with author.name