Ruby on Rails in a week


Finding out to Study, and references it just a few times—on the other hand, this publish must quiet quiet compose sense for those that passed over the first one. Additionally, right here is now now not an educational, but pretty a log of my expertise learning Ruby on Rails.)

I as of late stumbled on myself in a scenario the set aside I had 7 days to be taught Ruby on Rails. This changed into once mentioned quick in my old weblog publish, but I compulsory to take dangle of the time now to account for on this expertise.

My final weblog publish changed into once all about guidelines on how to be taught, and taking one of the best manner to learning. This weblog publish is ready striking those suggestions into narrate—a case look.

Contents hide

The Interview

First things first—I changed into once within the midst of an interview course of. It changed into once a Friday afternoon, and next Friday I could well well be taking piece in a reside coding narrate. Most of this narrate would appreciate working on a Ruby on Rails application. This meant that I had a 7 day crunch to be taught the framework.

You must well well also simply speculate on how I stumbled on myself on this scenario. Maybe it changed into once the end outcomes of some forgery or deceit. Maybe I had lied about my expertise in dispute to gain my foot within the door, and changed into once now left scrambling. Nonetheless alas, no. It changed into once now now not all that appealing. There changed into once no dishonesty, and no glum behaviors. As but every other, it changed into once a shared notion between me and interviewers that I changed into once bringing no preexisting recordsdata of Rails.

The settlement changed into once that I’d be taught a novel expertise, they normally would appreciate me on how well I picked it up. I’d be taught, but now now not grasp, the expertise, they normally would grasp my greenness into myth whereas assessing my recordsdata.

As such, I reasoned that I wasn’t surely being examined on my recordsdata of the Rails framework. No doubt, when the time came, I’d own to trace some degree of helpful recordsdata. Nonetheless if that changed into once all that they were procuring for they also can simply want staunch quizzed me—given me a competency take a look at or something of the admire. Nonetheless as a replacement, they compulsory to overview a rather more well-known potential—they compulsory to seem at me be taught.

This potential to be taught novel applied sciences is high to being a a success instrument engineer.

But, to boot-known as it could perchance well also simply be, gauging any person’s potential to be taught is advanced! You would’t absolutely realize a person or the soft expertise they also can simply want from a straightforward résumé or conceal letter. And technical interviews, no topic the rigor, turn out missing the point to boot.

EelADOtWkAEVZ6o

Describe by Vincent Déniel, on Twitter @vincentdnl

I’ve never felt represented by technical assessments, or interviews which be aware foolish suggestions (admire the STAR manner). Nonetheless by alongside side a learning course of within the interview (i.e., learning Ruby on Rails), it gave me a gamble to utterly notify myself. It benefited both of us. They were able to take a look at me on some very well-known, but tense to quantify expertise, and I changed into once able to notify myself in a kind that I in most cases would own now now not been able to.

The Way

As I believed of the interview and what I changed into once surely being evaluated for, I began to invent a intention—a mind role.

The way in which wherein I’d manner the next 7 days changed into once very intentional.

I role out to take dangle of a greater-stage manner to the educational, and, at some stage for the duration of, remind myself to specialize within the ideas, the larger image, and the way in which the things I’m learning show to my existing recordsdata. This changed into once novel ground for me. For the first time in my profession, I changed into once now now not staunch aware of what I changed into once learning, but how I changed into once learning.

To better summarize some aspects of the manner I could well well be taking:

Focal point on the ideas—judge bigger

For instance, grasp the theorem that of inheritance. Low stage thinking could well well sound admire, “The total other classes are adding if they would favor to make exhaust of this form, so I must enact that too. Otherwise it throws an error.’’

Nonetheless excessive stage thinking could be more admire, “I must entry the ApplicationController class’ suggestions. Ruby supports inheritance, so I’ll add  to the class definition to let the compiler know that I’m inheriting it.”

Compare and contrast

This could be very simple things, like “In Python it’s None, in Javascript it’s null, but in Ruby it’s called nil”, or making connections like “oh, this is like Rail’s version of pip, or npm.”

Be curious

“I haven’t seen anything about string interpolation, I wonder if Ruby supports some version of that?”

“How would I do something like this in Python? Javascript? Would it be easier or harder?”

Anticipate

“Rails generates a lot of functions and methods for you that aren’t defined in the code—I bet that will be hard to debug.”

Be active

I like to take handwritten notes to make sure that I’m not daydreaming, or just moving my eyes over words. If I’m being really purposeful, I like to do the little bonus activities and exercises that tutorials or textbooks often include. Sometimes they’re silly, and feel wasteful, but they do force me to be active, to think about, and to use what I’m learning.

Take it slow

Everyone has their own pace, and increasing that pace too much can degrade the other aspects of learning. I find that when I speed up too much, I stop taking notes and start skipping over useful activities. I get lazy, and I don’t learn as much. Moving at a healthy pace, and also taking breaks when needed is very important.

The Approach (continued)

Being able to take a step back and approach a problem at a high-level like this was a significant milestone for me. Simply put, when you’re learning your first programming language, you don’t have anything to compare it to. The only things that you can focus on are the low-level details—things like syntax, iteration, and data structures.

It’s possible, however, that a learner never graduates from this mindset. A developer could know three, four, or more languages on a functional level, but still be unaware of the concepts.

It might be that up until this point, I just didn’t have enough experience to see the bigger picture. Or, though I hate to say, maybe I was the developer who never graduated from the mindset of memorizing low-level details. Or it could’ve been that I was thinking about concepts, taking apart information, and categorizing knowledge, but I just wasn’t very conscious that the process was taking place.

But for whatever reason, when I set out to learn Ruby on Rails, I was acutely aware that I had a new approach to learning. It’s like I had hiked up to a new vantage point. After hacking my way through a forest where all I could see was the vines and foliage, I now stood atop a mountain, with a clear view of where I had been, and the trails I had walked.

Armed with my new mindset and approach to learning, I couldn’t wait to start.

Resources

Michael Hartl’s Ruby on Rails Tutorial was the main resource I used when learning Rails. It’s a very impressive learning tool that leads you through building what is essentially a Twitter clone. Unfortunately it’s not free (apparently it used to be—I guess I missed out on that), however I believe that the $31 price tag to gain access to the online version is well worth the investment.

I also consulted the Rails API Docs a few times when I was feeling curious, or looking for more specific information on a certain Rails module. Thanks to the tutorial, I didn’t really need to dive too much into the docs, but I think it’s always good to get familiar with the source documentation of any language or framework you’re using.

And of course Google, which led me to Stack Overflow, GitHub issues, and random blog posts.

Setting Up The Environment

I started by downloading Ruby, which brought me my first few lessons.

Firstly, I learned that Ruby is a programming language! Well, I sort of already knew this, but before this moment some smooth-talker could have convinced me otherwise. You know when you kind of think you know about something, you’ve heard people talk about it, but you don’t actually know about it? I had never used Ruby, and I had never really had a reason to. So as elementary as it may sound, this is where I started—with the recognition of Ruby as a language.

Building on that knowledge, I learned that Rails is a web framework that is written in the Ruby programming language. Now we’re getting somewhere! I’m starting to understand the components that make up Ruby on Rails, and I can relate them to what I already know. Saying Ruby on Rails is kind of like saying Javascript on React (although that doesn’t quite have the same ring to it, does it?).

My next run in with curiosity—is there a version manager I should be using?

I am familiar with nvm and pyenv for managing Node and Python versions, respectively, however the tutorial I was following did not mention any Ruby version manager. I took to the internet and found the highly popular, rbenv.

Perfect.

With rbenv in hand, installing Rails came easily and generating a project was a breeze. I found the rails new command to be powerful, automated, and that it gave me everything I needed to get a project up and running in the browser. It’s always nice to see some sort of early success, even if it’s “Hello world!”, or in this case, “Yay! You’re on Rails!”. I likened it to my experience with npx create-react-app, which generates a simple React application.

Directories and File Structure

My first impression after generating a project—“There’s a lot going on.”

Generating a Rails application resulted in 46 directories and subdirectories, and 89 files. Some of these files were familiar to me, like a README.md, and the public/ folder which holds the standard 404.html and favicon.ico. But most of everything else was uncharted territory.

To make things simpler, we can try and strip down the excess and focus on the core of the app. Arguably the most important directory—where you can find the meat and potatoes of the application—is the /app directory. But even there it’s hard to get an idea of what’s going on.

Here’s what you see in the /app directory after generating a new application—

├── app
│   ├── assets
│   │   ├── config
│   │   │   └── manifest.js
│   │   ├── images
│   │   ├── javascripts
│   │   │   ├── application.js
│   │   │   ├── cable.js
│   │   │   └── channels
│   │   └── stylesheets
│   │       └── application.css
│   ├── channels
│   │   └── application_cable
│   │       ├── channel.rb
│   │       └── connection.rb
│   ├── controllers
│   │   ├── application_controller.rb
│   │   └── concerns
│   ├── helpers
│   │   └── application_helper.rb
│   ├── jobs
│   │   └── application_job.rb
│   ├── mailers
│   │   └── application_mailer.rb
│   ├── models
│   │   ├── application_record.rb
│   │   └── concerns
│   └── views
│       └── layouts
│           ├── application.html.erb
│           ├── mailer.html.erb
│           └── mailer.text.erb

This was the dark side of automation. When the work is done for you, you don’t have to understand it.

But as I followed the tutorial, I began to pick up on some familiarities. I was at first confused by the .html.erb file extensions littering the project, but then learned that ERb is an HTML file with Ruby code embedded in it. That makes sense—I’m familiar with the concept from PHP files, or the JSX that’s used in React. And the Gemfile is the equivalent of other manifest/dependency files that I’m used to such as Node’s package.json and Python’s requirements.txt.

These are just a couple examples, but similar thought processes followed.

There was certainly a learning curve, and it took me a while to get comfortable, but the Rails directories structure began to make sense over time. And (spoiler alert!) it turns out that this standard directory structure is actually one of my favorite things about Rails. It lets you hop into almost any Rails project and quickly get a sense for what’s going on. This seems to be a common theme with Ruby on Rails—something seems very intimidating or confusing at first, but after getting over the learning curve, it becomes a very useful element of the framework.

Model-View-Controller

I had never used the Model-View-Controller design pattern before Rails. I had heard of the idea from Android Studio and Android app development, but hadn’t really gotten to know it too well. It can be thought of as—

  • Models for handling data and business logic
  • Views for handling graphical user interface objects and presentation
  • Controllers for handling the user interface and application

The tutorial I was following described MVC as an, “…architectural pattern, which enforces a separation between the data in the application (such as user information) and the code used to display it.”

Since I was trying to focus on high-level thinking, this high level view of the architecture of Rails applications stuck out as particularly important. This was exactly the type of thing that, if I was being lazy, I could probably skim over and not pay too much attention to. And without ever learning the importance of MVC, I could still probably manage to build Rails applications, but they would be messy. They wouldn’t work as well, would take longer to develop, and would be harder to maintain.

So I took my time, took notes, and I let the MVC knowledge settle in.

In Rails, they’re conveniently separated into files in separate directories.

├── app
│   ├── controllers
│   ├── models
│   └── views
│   └── (several other directories)

It would take some actual, hands-on development for me to get a practical understanding of what MVC meant, because abstract knowledge is often different from practical knowledge, but it was now something that I was aware of as I began programming.

Later on I would learn of the “skinny controller, fat model” mantra, and since I had already been in the MVC mindset, this actually made a lot of sense to me. I adjusted my development strategy accordingly. If I had ignored the high level architecture, I might have just thrown all of the logic into the controller. I wouldn’t have understood what was meant by “skinny controller, fat model”, my projects would have suffered, and perhaps worst of all, I could have embarrassed myself in front of other developers!

The Magic of Rails

This has been a topic of great discussion for as long as Rails has been around. Ruby on Rails is confusing to newcomers, and it has been described as, “too magical”. I, too, was confused at first. All over the application, there were references to functions or files that I couldn’t find definitions for.

Rails feels magical because it does a lot for you. It imports things, renders things, passes instance variables from the controller to the view, and more. Just adding a resource to the routes.rb file (i.e., resources :users), adds seven different routes for CRUD operations. There are the reusable partials, which are special types of views indicated by an underscore at the beginning of their filename. And don’t even get me started on the magic involved when has_secure_password is added to a model.

It’s intimidating! People can, and do, say things like, “if you think Rails is magical, you just haven’t read the documentation.” Kudos to the people who can sit down, read, and understand documentation that easily, but I know that, for me, I had to experience it first hand before it began to make sense.

But with practice and research, the magic fades away. All of the implicitness, abstraction, and “magic” in Rails serves a purpose. It’s not just there to be confusing. After becoming comfortable, the payoff is that development is fast, time consuming tasks are lifted away, and the developer’s quality of life is high. Being able to utilize the magic of Rails becomes a sort of superpower.

That being said, there are potential downsides. Firstly, the steep learning curve is a barrier to entry for those looking to use Rails. There is also the risk, especially when it comes to metaprogramming, that code can become too complex and errors too hard to trace. Ruby on Rails is a framework where code can do the exact same thing but look so very different, which can make it hard to maintain a project, especially across a development team where multiple individuals are contributing.

Ruby

The Ruby language could have its own dedicated post, so I’ll limit myself to the three things that stuck out to me the most.

Everything is an object

This is not entirely true, but it’s mostly true. Ruby is extremely object-oriented. Of course there’s exceptions (like if statements, or flow control keywords such as break and continue), but still, mostly everything is an object. And objects have classes. And classes have methods.

As a fun little experiment, we can inspect the nature of the number 1—

1.class=> Integer

1.class.superclass=> Numeric

1.class.superclass.superclass=> Object

And sooner or later, 1.class.superclass.superclass.superclass=> BasicObject

The same could well well moreover be achieved with nil

nil.class=> NilClass

nil.class.superclass=> Object

nil.class.superclass.superclass=> BasicObject

So both the integer, 1, and the nil object, nil, sooner or later inherit BasicObject. And, as it goes, anything that will be a subclass of BasicObject has entry to BasicObject’s suggestions. I staunch judge that is so chilly. All the pieces has a frequent ancestor–there’s a form of oneness to all of it.

Return values

In Ruby, you want to to possibly perchance well presumably print to the console the exhaust of puts “Hiya World!”. This by myself isn’t very attractive, but for those that look the conduct of puts, it shines a lightweight on the internal machinations of Ruby.

Calling puts will print a string, but afterwards the manner will return nil.

Ruby is irregular on this form, and it’s well-known for a developer to be very aware of this peculiarity. In Ruby, all the things evaluates to a impress. The puts manner must return something, so it returns nil.

And within the suggestions that you just’re writing, if there’s now now not a return name, what finally ends up being returned could well well be the final evaluated half of code within the manner.

This conduct changed into once very assorted from other languages I’ve used earlier than, and stuck out to me as very well-known—it’s a fundamental component of Ruby. No longer notion an factor of a language comparable to this could perchance presumably trigger many of frustration and heartache extra down the motorway.

Blocks

Blocks are one in every of essentially the most advanced, but most extremely fine aspects of Ruby. They support you neighborhood expressions, attach them to a variable, and even creep them to a kind. I’m quiet getting used to blocks and realizing their usefulness, but overall I surely feel that they condense hundreds of code, and likewise compose code more reusable and extensible.

That being mentioned, capable now I continuously staunch exhaust blocks for straightforward iteration.

For instance—

10.times { "Howdy y’all" }

Or iterating over an array—

[‘h’, ‘o’, ‘w’, ‘d’, ‘y’].every enact |letter|

puts "#{letter} is within the block"

end

Takeaways—What I Indubitably Admire

I alluded to this earlier, but one in every of my favourite things about Ruby on Rails is the list structure. It changed into once overwhelming originally, but now it rev

Read More

Similar Products:

Recent Content