P
P
pup_pupets2014-08-18 10:46:23
Ruby on Rails
pup_pupets, 2014-08-18 10:46:23

What's a good practice to create "your" functions in Rails?

Hi
I'm migrating from java to rails here and I don't understand the organizational issue. Well, earlier, in java, if I needed some kind of dedicated logic, then a package was created and everything was stored there. By "everything" I mean beans, some utils, maybe separate classes for working with other objects of other classes.
In rails, on the other hand (possibly only at first), I got the impression that everything is rigidly tied to MVC, where you describe some kind of logic either in the model or in the controller. But where to store your classes and everything that usually lies in the package? What is the best practice in this case?
Thanks in advance to those in the know.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vsuhachev, 2014-08-18
@pup_pupets

In addition to the lib directory and your gem mentioned by colleagues, you can separate classes into subdirectories in app. Unlike lib, all app subdirectories are autoloaded by default, so you don't need to write require manually. Well, in terms of meaning - in app they place something that relates directly to the current application, and in lib - either code from "third-party manufacturers" or their own code that is more independent of the current application with an eye to highlighting and using it in other projects.

S
Sergey Krasnodemsky, 2014-08-18
@Prognosticator

Take out your classes in a separate folder in / lib and include the folder in autoload
Or in gem if the code is a kind of extension of the framework.

M
Marat Amerov, 2014-08-18
@amerov

the architecture in the rails out of the box is primitive.
I recommend looking at
https://github.com/drapergem/draper
https://github.com/apotonick/cells
https://github.com/collectiveidea/interactor
and also look at how modules are arranged in ruby.
it also happens that the project is divided into several applications

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question