Answer the question
In order to leave comments, you need to log in
What is the best way to implement 1:N communication in a RoR project?
Hello!
One news can be in several categories (have several IDs of different categories).
To do this, you need to use the third table - categories_for_news - with the fields: id, news_id, category_id.
At this stage, everything is clear. The question is this: "What is the best way to organize this in a RoR project?"
I mean, is it necessary to create a model for this case. In general, I am new to RoR, and I would like to ask you for a piece of code with this implementation as an example, as well as accompanying comments.
Thank you in advance.
Answer the question
In order to leave comments, you need to log in
You need to create 2 models Categories and News and organize a many-to-many relationship. How to do this is written in the documentation with examples: Has_many
:through
relationship Has_and_belongs_to_many relationship
Choosing between has_many :through and has_and_belongs_to_many
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question