Answer the question
In order to leave comments, you need to log in
How to properly organize the architecture?
There is an application on Rails. Created separate models for announcements, news and announcements. The question is, is it worth making three separate models, or is it possible to only have one, because in fact there will only be name and content fields? but in the future, you may need to add other fields, such as price for announcements and date or venue for announcements. How to make it more flexible but also to minimize duplication?
Also, these models should be tied to categories. I think to name the parent categories Announcements, News, Announcements. And to their descendants to bind the objects of these three models, respectively. I implement subcategories using https://github.com/collectiveidea/awesome_nested_set/
Answer the question
In order to leave comments, you need to log in
You can leave each model as a separate class and use concerns.
# app/models/news.rb
class News
include Entry
end
# app/models/announce.rb
class Announce
include Entry
end
# app/models/concerns/entry.rb
module Entry
extend ActiveSupport::Concern
included do
belongs_to :category
end
end
If your news, announcements and announcements are similar entities, then create a Content model and use STI
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question