I'm working in Rails 5.
In my database, I have a table called publications and a table called authors which have a HABTM relationship.
I want to build a form that lets users insert more publications into my db, and part of this is associating existing (or new) authors to each new publication.
What's the best way to do this?
Here's my relevant code:
publication.rb
class Publication < ApplicationRecord
self.table_name = "publications"
has_and_belongs_to_many :authors
end
author.rb
class Author < ApplicationRecord
self.table_name = "authors"
has_and_belongs_to_many :publications
end
_form.html.erb
<h3>Publication name:</h3>
<p><%= f.text_field(:name) %></p>
<h3>Authors</h3>
<p><%= ??? %></p>
<h3>Citation:</h3>
<p><%= f.text_field(:citation) %></p>