i have personally used concern in poymorphic associations and when i want some special behavior in several model, and i use module to declaree functions that i need to use in my controllers or services, working with component in rails i make a metaproming module to declare instance variables witth a default values making a merge of all parameters the component can recieve
I think we can also use concerns in a controller to separate all methods that are not a direct action of the controller. For example a method to generate a cookie would go in the concern, while the action that uses it would obviously be in the controller. This is necessary because we can't use helpers in controllers. What do you think about this practice?
You don't really need that include in the controller if you are using the "static" method calls. You can think of include method pretty much as defining the methods in the module in the context of the class where it is being included. This won't apply for `def self.xyz` methods though. You can operate with the `def self.methods` in similar form using the extend method but the result affects the class not the instances (as include would). This rabbit hole goes a bit deeper, it is meta-programming all the way down. It would become a book on this comment.
I am new to rails and was about to ask... With no including, and no extending going on here... Wouldn't this just be a require? I guess the include brings it into scope even if it's not actually including instance methods.
This helped me understand better something I already thought I understood.
Thank you very much! I always watch your videos. They help me a lot!
i have personally used concern in poymorphic associations and when i want some special behavior in several model, and i use module to declaree functions that i need to use in my controllers or services, working with component in rails i make a metaproming module to declare instance variables witth a default values making a merge of all parameters the component can recieve
I think we can also use concerns in a controller to separate all methods that are not a direct action of the controller. For example a method to generate a cookie would go in the concern, while the action that uses it would obviously be in the controller. This is necessary because we can't use helpers in controllers. What do you think about this practice?
Always super helpful videos. Thanks.
Happy to help!
You don't really need that include in the controller if you are using the "static" method calls.
You can think of include method pretty much as defining the methods in the module in the context of the class where it is being included. This won't apply for `def self.xyz` methods though.
You can operate with the `def self.methods` in similar form using the extend method but the result affects the class not the instances (as include would).
This rabbit hole goes a bit deeper, it is meta-programming all the way down. It would become a book on this comment.
I am new to rails and was about to ask...
With no including, and no extending going on here... Wouldn't this just be a require? I guess the include brings it into scope even if it's not actually including instance methods.
thanks for sharing
What is the editor theme name ?
Spacegray 80s I believe
keep going 🫡