X
X
xskif2015-04-01 23:17:13
Ruby on Rails
xskif, 2015-04-01 23:17:13

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

3 answer(s)
I
Ilya Bondarenko, 2015-04-02
@xskif

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.

V
Viktor Vsk, 2015-04-02
@viktorvsk

how to use them to group code in Rails without creating a gem

You are probably taking the word module too literally.
If you want to group code - group separately models, separately controllers, separately helpers, separately views.
Want to group applications, routing - gems, enjains.
In the form you imagined - app/modules/user/... - how did you imagine working with static files? What about environment settings? What about routing? After copy-pasting this directory into another application - manually correct the routing file?

W
webbus, 2015-04-01
@webus

django reusable apps

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question