Ruby on Rails Lingo

Just as France’s Train à Grande Vitesse (TGV) (traveling at speeds of up to 320 km/h) dramatically reduces travel time for modern day rail passengers, Ruby on Rails (a.k.a. “Rails”) substantially reduces the time and effort required to build powerful web applications. - Toptal

What is Ruby On Rails?

Ruby on Rails is a framework for building clean and secure web apps quickly. With RoR, you can build a app easily using “beautiful code”, or code that is clear on what it’s doing and easy to understand. It’s built with the Ruby programming language, which is well known for beautiful code. I love Ruby because rather than spending all of my time dealing with syntax issues, I can spend more time learning programming concepts with code that I can read and understand quickly. As an example, say I’m a kid trying to get my mom’s attention, and I know it takes five times to say her name before I get it. In Java, my statement would look something like:

for(int times = 0; times < 5; times = times + 1) {
  System.out.println("Mommy!");
}

It’s not terribly complicated, but Ruby is much more clear:

5.times { puts "Mommy!" }

Rails Believes in Convention Over Configuration

Ruby on Rails is considered to be a very opinionated framework due to the principle of Convention over Configuration. Straight from the Ruby on Rails Guide they explain this concept: “Rails has opinions about the best way to do many things in a web application, and defaults to this set of conventions, rather than require that you specify every minutiae through endless configuration files.”

Rails allows you to focus on the purpose of your app, rather than spending time configuring every detail and having to know this information upfront. I don’t have to know all about Security before I build a hobby app because Rails has the security basics already handled. Rails also makes dealing with databases easy. Where database changes would usually cause a headache in dealing with configurations, Rails uses Ruby magic with Active Record. It’s common for ex-PHP developers to mention that they escaped to Rails from PHP’s complexity.

“Powerful web applications that formerly might have taken weeks or months to develop can be produced in a matter of days.” – Tim O’Reilly, Founder of O’Reilly Media

Who Is Using Ruby On Rails?

Twitter was among many of the popular apps built on RoR, although they’ve switched over a lot of code to Scala(Java). GitHub, the most popular online code repository uses Ruby on Rails as well as Shopify, an e-commerce hosting site. In fact, according to Builtwith.com, 1.9% of the top 10k websites are built with Ruby on Rails.

Current Rails Demand

In November 2014, Quartz released data showing that Ruby on Rails tops the chart of valued programming skills by salary. While the data may not be completely accurate and will change over time, it still shows that Ruby and Ruby on Rails are currently key players in the programming world. Learning it surely won’t hurt a software developer’s salary. Salaries By Programming Skill

Jumping into Rails can be a little complicated if you’re not used to the common terminology. I wrote this blog to clear some of those terms up.

Web Applications

A web application is distinguished from a website in that it has added functionality. A basic website has pages & content but does little more than that. A web app may take content from you and apply some kind of “business logic” to it which decides how that information is created, displayed, stored, or updated. There is a common acronym for these 4 options called CRUD:

  • C - Create: Creates new content & stores it somewhere, usually in a database. This may be adding a new tweet or saving a new blog.
  • R - Read: Grabs the content to be viewed. This may be viewing a tweet or blog.
  • U - Update: Updates existing content. This would be editing a blog that already exists.
  • D - Destroy: Deletes existing content. This would be deleting a blog or tweet.

Facebook, Amazon, and Google are all examples of web applications. You’re not going there to read a static page, you’re going there to get something done. Rather than starting from scratch, an easy way to get up & running quickly is to use a framework. Ruby on Rails is a Web Application Framework.

Framework

A framework is a software skeleton that has some features and functionality to help you start writing your application code. Having a website respond to visitor’s requests can be some very tricky business especially when you add a database, add features that interact with visitors, and are dealing with security and authentication. Without a framework, you’d have to take care of every single detail yourself, whereas a framework like Rails handles all of this for you or makes it easy to set it up. Ruby on Rails is a type of framework called a MVC Framework standing for Model, View, & Controller.

Model View Controller Framework(MVC Architecture)

To understand an MVC framework, I’ll use the analogy of a restaurant. You’re sitting at a table looking at the menu. You decide that you want a steak, medium-well, and a martini, shaken-not-stirred, and you tell the waiter your order. The waiter takes your drink order and gives it to the bartender and takes your steak order to the chef. The bartender makes the drink, the chef makes the steak, and the waiter brings both to your table.

Views

In our analogy, the View is the menu. On a website, the view is the page that the user sees. When you fill out a form on a website, this is the equivalent of giving your order to the waiter.

Controllers

In our analogy, the Controller is the Waiter. A controller knows where to take instructions, but it doesn’t know how to complete the instructions. In the restaurant, the waiter knows where to take the drink order and where to take the steak order, but the waiter does not know how to make the drink or the steak. That is is the job of the chef/bartender(the Model).

Models

In our analogy, the Model is the Chef & Bartender. Models contain the business logic of an application, essentially the code that distinguishes what your app does. The Chef knows how to take the order of a Steak, medium-well, and return the expected result. In the same way, the Bartender knows how to take an order of a martini, shaken-not-stirred, and return the expected drink. The controller takes back the results and returns it to the view.

Active Record

A Rails application is written in Ruby, but it interacts with a database that requires a different language, often SQL(stands for Standard Query Language). Active Record allows you to take a Ruby Object and communicate it with data in a database. Say your app has Users, rather than having to write SQL statements to access a user named ‘Alex Kitchens’ like:

 SELECT "users".* FROM "users"  WHERE "users"."name" = "Alex Kitchens"

Active Record allows you to write:

User.find_by(name: 'Alex Kitchens')

Active Record allows you to do complex requests simply, and it’s worth learning the details of Active Record to improve your apps.

How Can I Learn Ruby on Rails?

Learning Rails can be a process, but there are a number of great resources online to get started.

  • Code School - I started with Code School’s “Rails for Zombies” and I liked it so much that I started a membership with Code School.
  • Rails Guides - This is one of the best resources for getting started. I still peruse the Guides weekly when I’m working on apps.
  • Agile Development with Rails 4 - I love the the Pragmatic Programmers books because they explain the concepts so well and they include fantastic general programming ideologies in each book. Their books make me better in the skill the book is teaching as well as a better programmer all around. This book is more technical and not quite a beginner book unless you are already comfortable with Rails basics or Ruby basics.

To learn Rails, you will have to learn a little Ruby as well. But don’t worry, Ruby is a lot of fun.

Learn Ruby

Here were my favorite learning resources when I was learning Ruby, in the order that I recommend them for someone new to Ruby.

  • Try Ruby - Another Code School tutorial, it’s based off Why’s Poignant Guide to Ruby. It’s great for the basics.
  • Codecademy’s Ruby Track - It’s pretty comprehensive and gets into some intermediate stuff like Procs & Lambdas.
  • Why’s Poignant Guide to Ruby - A hilarious introduction to Ruby and it’s definitely worth reading.
  • Ruby Koans - A command line introduction to Ruby written by the great late Jim Weirich.

I hope you enjoy learning Rails, and good luck to your future apps!

alex

About Alex Kitchens

I am a principal software engineer at Stitch Fix working remotely from Amarillo, TX. Talk to me about anything Rails, Ruby, Rust, or coffee.