Madison Rails
Command Line Cheat Sheet

Learning to use the Command Line

Once you’re up and running with a working Ruby on Rails installation, here are a few other command line “scripts” to keep handy.

Start Locahost

You may remember this from the other wiki page about installing RoR ( RoR Installation Cheat Sheet ) so here’s a quick recap at how to start your localhost server. You may have your Rails app running somewhere else, this is just an example.

At the C:\> type:
cd rails_projects\NameOfMyApp
... hit enter, then at the C:\rails_projects\NameOfMyApp> type …
ruby script/server

... wait a second or two and you should see the server start spitting out a bunch of code in the Terminal window. This is good, now leave this window alone while you work on your new RoR app.

Navigating on the Command Line

To change directories, you obviously need to use “cd” but here’s how to look cool:
C:\>cd ra (tab)
... which gives me:
C:\>cd rails_projects
... then I type the dir separator and the first few letters of my next dir:
/Na (tab)
... which now gets me to:
C:\>cd rails_projects\NameOfMyApp
... hit enter and you’re now in the NameOfMyApp folder. Wheeeeeee!

To build out your database (initial creation):

Ruby needs a database to do the cool stuff it does, but don’t worry, at first you will not need to know MySQL. Ruby writes MySQL for you when the following is typed:

ruby script/generate model "modelName"

Be sure to go into PHPMyAdmin and double check that Ruby did this correctly. Go to http://localhost/phpmyadmin

Edit database migration (build db):

Edit DB Migation means that you want to open your migration in a text editor and edit it.

db/migrate/modelName.rb

Update your database:

rake db:migrate

Build your controllers and related views:

Create a controller with views attached, type this:

ruby script/generate controller "controllerName" "viewName1" "viewName2"

Build out your scaffolding:

ruby script/generate scaffold "modelName" "controllerName"

For more info, Google it.