Learning Rails: Concepts To Know Before Starting
Tags: rails, ruby, webdev
Published: 2019-10-19 00:47:20

---
title: Learning Rails: Concepts To Know Before Starting
published: true
date: 2019-10-18 04:04:34 UTC
tags: Rails,Ruby,Web Development,rails
canonical_url: https://morgandadams.com/2019/10/18/learning-rails/
cover_image: https://www.textures.com/system/gallery/photos/Roads/Rails/28363/Rails0014_1_download600.jpg
---

## Me Learning Rails 

Learning Ruby on Rails has been a fun adventure so far. Yesterday, I finished the [Getting Started](https://guides.rubyonrails.org/getting_started.html) with Rails guide on [rubyonrails.org](http://rubyonrails.org) which teaches how to build a simple blog app. Surprisingly, it does a thorough job of covering a number of features from working with the MVC to setting up routes and basic authentication.

I often hear that Ruby on Rails has a high learning curve – I want to dispute that. After finishing the guide, I feel confident I can start building my own apps using Rails and I think others can as well.

### Key Concepts to Learn to Understand Rails

Admittedly, if you know a few things before diving into Rails, it will make a lot more sense. I plan to cover some of those things here in this post. They are:

1. Model View Controller (MVC) design pattern
2. Web frameworks
3. Convention over Configuration

If you are already familiar with these concepts, go ahead and jump into the [Getting Started](https://guides.rubyonrails.org/getting_started.html) with Rails guide.

**_\*Note_** : You don’t need a lot of Ruby knowledge to start, although it certainly helps. Just having some basic-intermediate level programming experience in general would be a good start. With the heavy emphasis on convention, you don’t need much code to get functioning CRUD operations and relations.

\*\* **Disclaimer** : I’ve primarily been working in Operations, Site Reliability Engineering, and Security. So if my language isn’t precise on some of this, feel free [drop me a note](https://morgandadams.com/about/) so I can correct it.

## Model View Controller

First, lets look at MVC.

MVC is a common design pattern for the web. Although, you can see MVC in non-web applications it (and similar patterns) seems to be fairly ubiquitous around the web.

I won’t dive into a lot of MVC details since there exists an abundance of documentation on the subject, but I’ll cover some highlights.

**Models** are literally the object or idea you are trying to represent: an article, a search result, a goblin, a customer, etc.

**Views** are how you present information – specifically from the models. This often appears in the form of templates.

**Controllers** are the glue that tie models and views together. They take user requests, manipulate or retrieve models, and then render a view. In Rails, routes or URL paths map to controllers.

There is certainly plenty more on the subject and I encourage you to dig in more. Here are a few MVC articles to start:

- [Code Academy](https://www.codecademy.com/articles/mvc)
- [Wikipedia](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)
- [Tutorials Point](https://www.tutorialspoint.com/mvc_framework/mvc_framework_introduction.htm)

## Web Frameworks

If you think about what goes into building a web application, there are several common elements. Some of these are authentication, MVC, connecting to databases, input validation, and URL mapping – Wikipedia covers and links to more details [[link](https://en.wikipedia.org/wiki/Web_framework#Database_access,_mapping_and_configuration)]. Rails is such a framework and has a lot of these features readily available to help you focus on the business logic.

Because so much is implemented for you, you don’t always know the implementation details. That’s okay. Read the docs and play around with code examples. The behavior becomes apparent quickly.

Rails uses convention to conveniently tie the MVC part of the framework together. It might take a bit of getting used to it, but it’s achievable.

## Convention Over Configuration

Rails focuses on Convention over Configuration. Although it might obscure some implementation details, it means less lengthy configs.

Previously, I worked in setups where there are literally hundreds of config files. Ultimately, you end up with config files with outdated options and a new source of tribal knowledge.<mark id="annotation-text-7574b360-0424-459d-8478-778a25f93977"></mark>

For example, the Getting Started guide you run a command to create your model. This also produces a db migration file. After running the migration, you will have a table whose name is the plural of the model. Additionally, it’ll do all the mapping between model and table attributes (Object Relational Mapping). In the end, convention saves you a lot of setup.

The Rails folks cover Convention over Configuration philosophy really well [[link](https://rubyonrails.org/doctrine/#convention-over-configuration)].

## Getting Started With Rails

So now you know a little behind some of the key ideas behind Rails. Go follow their [guide](https://guides.rubyonrails.org/getting_started.html). It’s lengthy but it takes you from installation to a working app.

![screenshot of blog app](https://i1.wp.com/morgandadams.com/wp-content/uploads/2019/10/blog-screenshot.png?w=640&ssl=1)<figcaption>Screenshot of the blog app</figcaption>

When you finish, you will have worked with the MVC, routes, security, authentication, and a database. It’s just shallow enough to cover the important highlights and detailed enough to see how powerful it can be. Happy coding!

**\*NOTE** : On the installation, you’ll need to install a few extra dependencies: nodejs, yarn, ruby-dev, build tools, and libz-dev.

The post [Learning Rails: Concepts To Know Before Starting](https://morgandadams.com/2019/10/18/learning-rails/) appeared first on [Morgan Adams](https://morgandadams.com).