Other Pages

Expand All

Creating A Rails Application

Screenshot of a Ruby on Rails default home page

Goals

  • Create your new application

  • Let's get started! By the end of this step, we'll have a brand-new Rails app.

Steps

If you have any problems, contact a TA immediately.

Step 1

Make sure you have exited irb. If you haven't, your screen will say irb(main):001:0>. Leave irb by typing exit.

If you are using a virtual machine, make sure you are in it before continuing. If you are in the virtual machine:

  • Your command line prompt should be RailsBridge-VM:/vagrant$

If you do not see that command prompt:

  • Check to see if it is running by typing vagrant up
  • Enter the virtual machine by typing vagrant ssh

For Cloud9:

  • Your command prompt should look something like: ec2-user:~/environment

Ask a TA if you need help.

Step 2

Type this in the terminal:

Terminal
rails new suggestotron

rails new creates a new Rails project with the given name.

In this case we told it to create a new project called suggestotron. We'll go into detail on exactly what it did shortly.

Step 3

Type this in the terminal:

Terminal
cd suggestotron

cd stands for "change directory".

cd suggestotron makes suggestotron our current directory.

Step 4

Type this in the terminal:

Terminal
ls

ls stands for "list (stuff)".

It shows you the contents of the current folder.

Step 5

Let's look at the structure of the whole project.

You can see the project directory when you're using Sublime Text or Cloud9. This is convenient when you're going to edit several files and want to navigate quickly.

Screenshot of Suggestotron project folder tree in Cloud9

Open the suggestotron folder as a project in Sublime Text by clicking the Project menu and selecting "Add Folder to Project":

Sublime Text Project menu screenshot

Select your suggestotron folder from the file picker that opens. If everything works out Sublime should show the directories of your app in a tree structure on the left:

Screenshot of Suggestotron project folder tree in Sublime Text

You can see that rails new created a lot of directories and files. The ones we want to focus on today are:

File/Folder Purpose
app/ Contains the controllers, models, and views for your application. You will do most of your work here.
config/ Configure your application's runtime rules, routes, database, and more.
db/ Shows your current database schema, as well as the database migrations.
public/ The only folder seen to the world as-is. If you put files in here, they will be served directly without any processing by Rails.
app/assets/ This is where your images, JavaScript, stylesheets (CSS), and other static files should go. Modern rails apps use something called the Assets Pipeline, which combines all the JavaScript and CSS files in this directory into a single file for speediness.

There is a lot more that rails new created. Probably enough to fill a book, so we're going to ignore them for now.

Next Step:

Back to Ruby Language