How to make a model of products with different characteristics, as we say, do online stores with different product categories, and they already have products with different characteristics. A similar question, but without an exact answer.

  • You should first understand what a model is, think through some kind of project structure and, of course, learn the basics of OOP. Then such questions will not arise. RoR allows you to generate models using a standard generator. You can form such a structure - there is a category model and a model of products that have many to many connections, which fields the models have already decided. You can simply specify a field for the products in the form of a sheet ... In short, it depends on what you ultimately need - Naumov Ivan

1 answer 1

Not to say that I am a great spec at this, but I still get into it with my 5 kopecks.

If you have the opportunity for each new type of product (telephone, vacuum cleaner, etc.) to add a developer, along with all the characteristics, it makes sense to make them separate models inheriting from Product, so it will be somewhat easier with them work.

If admins should be able to create a new type of product in the admin panel and fill it with characteristics, then there is only one option - to store all this disgrace in the json-field (or better jsonb if using PostgreSQL). Quite a normal option, besides the fact that requests for it to do a little more difficult.

  • It would be great not only to minus the answer, but also to explain the reason for the negative vote - Vasilisa