Saturday, January 3, 2009

My first experience with Ruby on Rails

It's a new year, so I decided to learn a new language / environment. I chose Ruby on Rails,so here comes my experience.

I am following the tutorial at: http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html, which has been written for Rails 1.2.6. My environment thou is Rails 2.0. So, here are the steps I followed:

  • cd ~/Rails
  • rails cookbook2
  • cd cookbook2
  • rake db:create:all
  • ./script/generate scaffold Category name:string
  • rake db:migrate
  • ./script/server
Then point your browser to http://localhost:30000. It shows the RoR welcome page.

  • Go to file config/routes.rb and file the following line:
ActionController::Routing::Routes.draw do |map|
map.root :controller=> 'categories'
map.resources :categories

Now point your browser to http://localhost:3000/categories, and you are ready to create categories!

Creating the recipe table

  • ./script/generate scaffold Recipe category:references title:string description:string instructions:text
  • rake db:migrate
Now point your browser to http://localhost:3000/recipes and you're ready to create recipes!

No comments: