WTF Just Happened? A Quick Tour of your first Rails App
But then you get home and, after a few days, you take another look at your project. "What is all this stuff? I didn't write that!" There are so many folders and files, none of which you explicitly sat down and created. What are they all for?
After my first Rails Girls, I had this overwhelming desire to do an audit and remove what appeared to be superfluous code. The result? Well, predictably, my application broke and I had no idea what I needed to do to make it work again! It seems that all this "extra stuff" was necessary, after all. The only way I could get a working application again was rebuild it from scratch and not touch it. Being afraid to play with your app for fear of breaking it does nothing to help your learning.
This article will help break down what all this stuff is for and how it fits in. What you see here is a high-level overview, click on the links to read more detailed articles on each topic.
What is Ruby on Rails?
Rails is a framework for building web applications. It is written in Ruby. When you create a new Rails application, the framework part of it provides you with certain core functionality that is common to all web applications. It is this provided functionality that makes Rails awesome. And also makes Rails confusing for people who are learning. :-)
Along with the built-in functionality provided for you by the Rails framework, there is a library of Ruby gems that you can add to enhance your project.
A gem provides instant functionality and reduces the amount of code that you need to write. A bonus to using gems is that they've been tested by developers in many live applications. This means that you can exclude them from your automated test scripts. Trust me, one less thing to test is always a good thing!
Rails uses two files to manage gems:
Gemfile, which is a list of all the gems to be installed, and
Gemfile.lock, which is a list of all the gems, together with their version, that have been installed in your application.
See Gems and Bundler for more detail on this topic.
Configuration files allow you to customise the behaviour of your app. You will find them in the
config directory of your Rails app.
See Rails Configuration Files for more detail on this topic.
REST, MVC and Rails Routing
Rails achieves this with the following three folders:
and the file
When you typed
rails generate scaffold Post (or
Idea) in your Installfest (or Rails Girls) tutorial, you generated files that went into the models, the views, and the controllers folders. You also added a line to the
routes.rb file so that your posts (or ideas) could be accessed via a URL in your browser.
See Rails Routing for more details on Rails Routing.
Databases in Rails
Rails comes with SQLite database by default, and this is the database that we most commonly use in our development environment. When it comes to production, however, most developers will use something like PostgreSQL (arguably the most popular) or MySQL.
See Database Migrations for more information on Migrations.
See MVC: Model for more information on communicating with our database through the Model layer.
Rails uses a framework called the Asset Pipeline to compress these asset files. It is outside the scope of this article so it will not be covered here. If you are curious, please see Asset Pipeline for more details.
Other Useful Resources
This article is focussed on Ruby and Rails. However there are other concepts that you will need to understand to become a well-rounded Rails developer.
Below are some recommended resources for you to check out:
- An introduction to Object-Oriented Programming (OOP): object-oriented programming
- Instance variables and scope: Scope Wars
- A high-level introduction to git: The Big Picture of Git
- A detailed step-by-step guide to getting started with RSpec: RSpec Testing for Beginners, Part 1
That is your Rails project in a nutshell. This is intended to be a living document, and will be updated based on feedback from you. If you have any questions or comments, please comment below or email me.
The Benefits of Ruby on Rails
Heroku Forcing Password Resets as GitHub Investigation Continues
How to Maximise your ROI with a Custom Application Built in Sa...
reinteractive is Australia’s largest dedicated Ruby on Rails development company. We don’t cut corners and we know what we are doing.
We are an organisation made up of amazing individuals and we take pride in our team. We are 100% remote work enabling us to choose the best talent no matter which part of the country they live in. reinteractive is dedicated to making it a great place for any developer to work.
Webinars are our online portal for tips, tricks and lessons learned in everything we do. Make the most of this free resource to help you become a better developer.
The Ruby on Rails Installfest includes a full setup of your development environment and step-by-step instructions on how to build your first app hosted on Heroku. Over 1,800 attendees to date and counting.
The Ruby on Rails Development Hub is a monthly event where you will get the chance to spend time with our team and others in the community to improve and hone your Ruby on Rails skills.