Best Approach for Updating Attributes On Join Table
I have a view (show) that display's an Article. The Article has several Author[s]. The Article and Author models look like this:
Article Model has_many author_articles has_many articles, through: :author_articles Author Model has_many author_articles has_many author, through: :author_articles AuthorArticle Model belongs_to article belongs_to author
The join table (AuthorArticle) contains an article, author id columns, and another column called position_id. The Position model is also a has_many through. It looks like this:
Position Model has_many author_articles has_many positions, through: :author_articles Author Model has_many author_articles has_many author, through: :author_articles AuthorArticle Model belongs_to article belongs_to author belongs_to position
Here's what I would like to do and I am not exactly sure how to implement it. I would like to click on the author's name from the article show view, open a modal (already done) and have a form (SimpleForm) where the user can select a position (first, second, third, etc...) and press submit. The order of the author is important. Yes, there can be several "first/lead" authors. The form post would update the join table (AuthorArticle) position_id column with the position selected. Authors are added when a new article is created or updated.
Does this make sense? Let me know if you need more context? Something doesn't feel right about this approach and I'm open to suggestions/feedback/ideas.
You can add a
position:integer to your AuthorArticle model to keep track of the order.
acts_as_list gem can help you order them, but that wouldn't allow for duplicates where you might have several "lead authors". You can probably do without it.
The modal would be for an AuthorArticle object and would have two fields for author and position.