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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -