the behavior in Rails is likely to have its root in the difference between include and extend. When using include you need the object to be initialized, while extend does not require the object to be initialized to call a method. I would not be surprised that in Rails the validation is taking place before the object is initialized, thus the use of extend and the include do block.
Super proficient coding. Thanks for going through this. The only questions I'm really left with pertain to the "why" of it. Should we ~always~ be using concerns for Rails now? When is it better to just have a module or something shared that lives in the lib directory? And how do we determine what belongs in a model concern versus a controller concern?
Not really always using concerns for everything. It's a bit hard to explain, but my suggestion is just keep coding. Most likely you'll end up writing something that's difficult to maintain or work with, and you'll end up learning that way. As far as what belongs in a model vs a concern, if the code can be shared it should go in a concern, if code is specific to that domain model, it should be in the model. As far as code controller, you don't want much domain logic in there as a general rule.
the behavior in Rails is likely to have its root in the difference between include and extend. When using include you need the object to be initialized, while extend does not require the object to be initialized to call a method. I would not be surprised that in Rails the validation is taking place before the object is initialized, thus the use of extend and the include do block.
Great video man! What a great explanation about this two features. I saw a project where modules are located on lib folder and are used as concerns.
Super proficient coding. Thanks for going through this. The only questions I'm really left with pertain to the "why" of it. Should we ~always~ be using concerns for Rails now? When is it better to just have a module or something shared that lives in the lib directory? And how do we determine what belongs in a model concern versus a controller concern?
Not really always using concerns for everything. It's a bit hard to explain, but my suggestion is just keep coding. Most likely you'll end up writing something that's difficult to maintain or work with, and you'll end up learning that way. As far as what belongs in a model vs a concern, if the code can be shared it should go in a concern, if code is specific to that domain model, it should be in the model. As far as code controller, you don't want much domain logic in there as a general rule.
Really great videos, thank you so much!
Thanks
Thanks!!!
Thanks