mysql - Rails: How do I make a form that updates two HABTM tables at once? -
i'm working in rails 5.
in database, have table called publications
, table called authors
have habtm relationship.
i want build form lets users insert more publications db, , part of associating existing (or new) authors each new publication.
what's best way this?
here's 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>
Comments
Post a Comment