What is the difference between using problems with modules in rails?

Just now I started using Concerns on rails, but I doubt why we are following concerns, because we can achieve the same thing in the concept of modules and mixing. Therefore, please, someone will tell about shat, this is using problems instead of using a module.

+6
source share
3 answers

ActiveSupport::Concern adds some convenient functions to your module (for example, class_methods ). You can use pure ruby โ€‹โ€‹modules without extension. Essentially, you create a module that you mix with a class. It does not matter if this module extends to AS :: Concern, the mechanism is the same.

+2
source

Well described here: http://api.rubyonrails.org/classes/ActiveSupport/Concern.html

In short:

  • It allows you to use #included and #class_methods instead of self.included hook with the addition of an additional module ClassMethods ;

  • This gives better resolution of dependencies for modules included in each other;

+1
source

when you write in worry, which means that you are making one module. My opinion is a concern, and the module will be similar. The concern may appear somewhere as a model, controller, and here you can write a module for yourself. And with the general module it is written to the lib folder. Both can be used by inclusion or expansion in a class.

0
source

All Articles