Getting Started with Rails

So after quite a bit of practice and learning ruby, we are finally writing Rails apps! WooHoo! I’m going to walk through a few of the steps to get a rails app up and running on your local machine.
Firstly, you need ruby and rails installed on your computer.
check this with
ruby -v
and
rails -v

These should tell you the current version of ruby and rails you have.

If you’re using rvm (ruby version manager), there are some extra steps that I’ll omit here.

So here’s how you create a rails app called ‘blog’:

rails new blog

I usually run this with a couple options:

rails new blog -TB

The -T options skips the built-in test unit, which I skip because I use rspec instead. The -B skips the bundle because I usually want to add a couple gems to the Gemfile before I bundle.

Anyway, you should now have a directory called ‘blog’, which you can cd into.

The models, views and controllers are all in the app/ directory.
There are several ways to generate these files.

If you want a quick and easy to set up all three, along with a database to tie to your model, you can run:

rails g(enerate) article author:string title:string body:text

The :string is optional, as string is the default.

This command will create a database migration for the object Article, which has the following properties: an author, and title, and a body. Rails creates all sorts of files for you in the models, views, and controllers folders. Before you start going into those files, you’ll want to run the migration with

rake db:migrate

You can also see what routes rails created for you with

rake routes

From here, you can start modifying your views, controllers and models to customize your app.

There’s obviously much more that I didn’t cover here in getting started with rails, but there are tons of resources out there. I used this one

Getting Started with Rails

Have fun on the Rails!

Advertisements

About Aaron Glasenapp

I am a freelance Web/Rails developer and a hard core recreational mathematician.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: