Rails 3 Blog Tutorial Posted on February 20th, 2011
This tutorial will cover the creation of a personal blog using Ruby on Rails 3. This tutorial assumes that you have Sqlite3, and Rails gem installed. There will be other applications used but their installation is explained as is needed. The Blog: First lets create our rails application and come up with some basic starting blocks for our blog.
$ rails new blog
$ cd blog
$ rails generate scaffold post title:string body:text
$ rake db:migrate
$ rails -s
The first two commands create the base rails framework. The next command is where you see a lot of the benefit of using Ruby On Rails, it automatically created the migration files, model files, controller files, and view files for our new entity Post
. Migrations are how rails tracks database schema changes. You can migrate the database to a latest schema version or roll down to a previous version. Rake db:migrate
is the command to make the schema changes for the latest migration. Rails -s
creates a simple webbrick server; this server is good for development, but not production. You should now be able to load http://localhost:3000 in your browser where you will be greeted by a friend rails page. Of course you probably don't want your users to see this page so remove public/index.html.erb and add a new route, 'root :to => posts#show
to your configs.rb
, seen here. Once you reload your homepage you should see the friendly rails scaffolding. Feel free to create your first post! Setting Up Authors on Your Blog