Rails Concerns vs. Modules and when to use each

  Рет қаралды 1,929

webcrunch

webcrunch

Күн бұрын

Пікірлер: 12
@BubblegumSneaker
@BubblegumSneaker 5 ай бұрын
This helped me understand better something I already thought I understood.
@repoles
@repoles 5 ай бұрын
Thank you very much! I always watch your videos. They help me a lot!
@IanBradbury
@IanBradbury 5 ай бұрын
Always super helpful videos. Thanks.
@Webcrunch
@Webcrunch 5 ай бұрын
Happy to help!
@haroldpepete
@haroldpepete 5 ай бұрын
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 5 ай бұрын
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?
@formigarafa
@formigarafa 5 ай бұрын
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 15 күн бұрын
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 5 ай бұрын
thanks for sharing What is the editor theme name ?
@Webcrunch
@Webcrunch 5 ай бұрын
Spacegray 80s I believe
@abdullahsaleh7196
@abdullahsaleh7196 5 ай бұрын
keep going 🫡
10x your chances of landing a Ruby on Rails Job
12:47
webcrunch
Рет қаралды 1,5 М.
ViewComponent Crash Course with Ruby on Rails
46:33
webcrunch
Рет қаралды 1,2 М.
I Turned My Mom into Anxiety Mode! 😆💥 #prank #familyfun #funny
00:32
龟兔赛跑:好可爱的小乌龟#short #angel #clown
01:00
Super Beauty team
Рет қаралды 138 МЛН
the balloon deflated while it was flying #tiktok
00:19
Анастасия Тарасова
Рет қаралды 36 МЛН
КОГДА К БАТЕ ПРИШЕЛ ДРУГ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 7 МЛН
Understanding Active Record Associations
15:16
webcrunch
Рет қаралды 35 М.
Modules vs Concerns
12:43
TypeFast
Рет қаралды 4,1 М.
The Right Way To Return API Errors in .NET
10:40
Nick Chapsas
Рет қаралды 41 М.
NextJS to Rails: The code that powers our new marketing site
14:30
Adam McCrea
Рет қаралды 2,9 М.
#178 NEW Rails 8 Authentication Generator
16:18
SupeRails
Рет қаралды 3,3 М.
All the ways to render partials in Rails
17:11
webcrunch
Рет қаралды 855
Comprehensive Guide to Modules in Ruby 3
20:57
edutechional
Рет қаралды 8 М.
How To Use Libraries Like A Senior Dev
9:53
Web Dev Simplified
Рет қаралды 33 М.
Ruby Basics: Symbols vs Strings
10:14
GoRails
Рет қаралды 10 М.
I Turned My Mom into Anxiety Mode! 😆💥 #prank #familyfun #funny
00:32