Modules vs Concerns

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 8

  • @stpaquet
    @stpaquet 2 года назад +6

    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.

  • @williamromerovela
    @williamromerovela 2 года назад +1

    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.

  • @Vangoghbothears
    @Vangoghbothears Месяц назад +1

    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?

    • @typefastco
      @typefastco  Месяц назад

      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.

  • @texaslinux
    @texaslinux 2 года назад +1

    Really great videos, thank you so much!

  • @muhammadahmed1890
    @muhammadahmed1890 2 года назад +1

    Thanks

  • @ledockol
    @ledockol 2 года назад +1

    Thanks!!!

  • @shinzhang4961
    @shinzhang4961 2 года назад +1

    Thanks