I'm not shure what's the right way to do this, so I hope to get some advice of how to do this 'nice'. Let's say you have a model with multiple relations as belongs_to-statements, for example a book. A book has a author (user) and a publisher:
belongs_to :user
belongs_to :publisher
Great. The user is signed to a publisher via a has many :through
has_many :contracts
has_many :publishers, through: :contracts
Same goes for the publisher model. Both, author and publisher have many books. So far so good. Now you have a publisher-show-view in which you render the book's form-partial, 'cause you want to add a book directly from the publisher's 'show'-view.
Now, you want to submit the form and cause to the relations, you have to feed the book model with the publishers and the authors-data.
The question is now, how to do this. Merging data into the params in the book's create method seems to work good: found on stackoverflow.
I've red about creating a hidden field in the form with the author_id but didn't go after it, cause it felt dirty somehow.
What would be the 'right' way to do this? Thanks in advance...