Rails Concerns vs. Modules and when to use each

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 พ.ย. 2024

ความคิดเห็น • 12

  • @BubblegumSneaker
    @BubblegumSneaker 6 หลายเดือนก่อน +2

    This helped me understand better something I already thought I understood.

  • @repoles
    @repoles 6 หลายเดือนก่อน

    Thank you very much! I always watch your videos. They help me a lot!

  • @haroldpepete
    @haroldpepete 6 หลายเดือนก่อน +1

    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

  • @MarceloAlarcon-tx6qe
    @MarceloAlarcon-tx6qe 6 หลายเดือนก่อน +2

    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?

  • @IanBradbury
    @IanBradbury 6 หลายเดือนก่อน

    Always super helpful videos. Thanks.

    • @Webcrunch
      @Webcrunch  6 หลายเดือนก่อน

      Happy to help!

  • @formigarafa
    @formigarafa 6 หลายเดือนก่อน +2

    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.

    • @eotfofiw2748
      @eotfofiw2748 หลายเดือนก่อน

      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.

  • @ahmed_aboelleef
    @ahmed_aboelleef 6 หลายเดือนก่อน

    thanks for sharing
    What is the editor theme name ?

    • @Webcrunch
      @Webcrunch  6 หลายเดือนก่อน +1

      Spacegray 80s I believe

  • @abdullahsaleh7196
    @abdullahsaleh7196 6 หลายเดือนก่อน

    keep going 🫡