Ruby on Rails Thursday, August 8, 2019

Well, in my particular case, I already understood the way that the controller accepts the incoming request and assigns the attributes. That understanding came from many many years of working in Rails.

The save part I understood intuitively, because years ago, I wrote an implementation of Active Record (the pattern: https://en.wikipedia.org/wiki/Active_record_pattern) in PHP. So I knew approximately where to look, and googled 'active record base save'.

That took me to a disambiguation page on APIdock, where I found out that the method had moved around a few times. I knew that the concept of saving something to the database is known in Rails as "persistence" (a model instance has the method `persisted?` on it, for example), so I picked the version of #save that was in the persistence module, and followed the source. Each listing in APIdock has the snippet of source code that implements that method, and each method in turn contained more sub-methods that further processed the request to save. I followed the trail down one path only (I didn't bother showing all the details of what happens when you try to save something that is already persisted, which makes an UPDATE query rather than an INSERT query).

I've been following Rails as a technology since it was publicly announced, back in 2005 or so. I tried it briefly at that time, found it "too hard" for a struggling PHP hacker, and put it aside for a long time. I discovered a solid implementation of the ActiveRecord pattern in PHP, and used it successfully for several years in my commercial work. When the developer abandoned it, I took over the project and further refined it.

When PHP 5.3 made that library stop working, I wrote a clean-room replacement that followed the newer rules of PHP's classes. After using that for a couple more years, and looking at a several fairly mature Rails clones in PHP, I finally decided to stop trying to use copies and go to the original. My skills had leveled up, and Rails' tooling had improved, to the point that we were now compatible.

I made a "bet" with myself that I would just use Rails for the next project that came through my door. This was a request for a document repository with multiple levels of authorization (some people could author, some people could approve, some people could read-only). This was a great fit for Rails and its constellation of RubyGems. At the end of that project, I ran `rake stats` on the project. I found that I had written ~170 lines of code, ~250 lines of tests, and everything else came from a Gem or the framework itself. For those lines of code, I was paid $17K. That was enough of a reason to dive in and never look back.

Walter

> On Aug 7, 2019, at 10:15 PM, Noel <noelirias@gmail.com> wrote:
>
> You just hit everything that I was trying to figure out and then some. This is what I've been needing to know(I can't be certain of the that). Last question, how did you figure that out?; because that's where this is kind of embarrassing, that I've held out to ask this for so long for fear. I'm sure intuition and experience comes with understanding what's under the hood, but how does a junior dev figure stuff out like this? Please be merciful, don't say look at the documentation, the documentation needs documentation. The documentation is not very clear for a junior dev because some stuff is abstracted and it's like you have to be in the know about some other concept(that is omitted because reasons) that isn't mentioned but understood.
>
> Goes without saying but thanks man, this is solid knowledge I can use.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cec8887e-7b38-4feb-b403-ef2810038a84%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3255E199-52BE-4B4E-91ED-0360032083CC%40wdstudio.com.

No comments:

Post a Comment