Re:Rails Is Good Enough
by tenacious_tuna on Saturday August 03, 2024 @11:41AM
(#41147217)
Coming from a paradigm of being able to read code and understand what it does, having to drop into console to poke at things, even just to then find the source for a given function, was extremely unintuitive to me.
At this point I always have a rails console up, just to be able to poke at objects and whatnot, but it feels... clunky. Similarly, when designing system changes I first go through with breakpoints in an existing flow to see what objects and behavior actually are when invoked, because I can't tell just from reading the code half the time--and that drives me bananas.
Say you want to understand what does `belongs_to` do?
Just open `rails console` and you can do:
And opening the file that is printed at the specified line, you can discover the following code: And moreso that method has a very good comment before the declaration, documenting everything it doesYou can also try `show_source` command in Rails console if you have the debug gem installed:
And this will directly show the source code of the `find` method.I do agree that for methods defined with meta-programming it will be harder to find the methods.
But again here rails console comes with help:
For example if you do:
Of course, this is mode complex meta-programming code, but you can still go to it, read it, and see what it does.In case of relationships between entities in the code, you can try Sorbet. It is pretty good these days.