Answer the question
In order to leave comments, you need to log in
How to organize code in Ruby on Rails into separate modules?
For several weeks now I have been trying to figure out how to organize code in RoR into separate modules, like self-contained applications. I am new to Ruby and Rails. I studied modules at the language level far and wide, but I still did not understand why they have two responsibilities (code grouping, embedding as traits) and how to use them to group code in Rails without creating a gem, but if only with the help of a gem, then how, nevertheless, to make a set of modules that I can reuse in other applications?
An example of what I want:
Create a User/Forum/Shop module. Path to the module, eg app\modules\user\[module files]
Within a module are its own directories for models, controllers, views, and helpers.
The ability to tell the router where to look (search for a module and its controller) when requesting mysite.com/user/[controller]/...
If Rails is not for this, then please tell me another good example of code organization.
Answer the question
In order to leave comments, you need to log in
Try to take a closer look at the Rails Engine ( rusrails.ru/engines )
The module (read the functional part of the application) that you write can be formatted as a gem, or you can simply connect it from a folder.
Connecting the application is to include it in the Gemfile, mount the application in routes.rb and run the migrations.
Most likely this is exactly what you need.
how to use them to group code in Rails without creating a gem
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question