My First Rails 2.0 Application w/ Restful Authentication

Today I took the plunge and installed Rails 2.0.2. Notes on the Rails 2.0 release can be found here.

Here are the steps I took.

  1. Upgrade Ruby Gems to the latest version (in this case 1.0.1).
    gem update --system
  2. Install Ruby on Rails 2.0.2.
    gem install rails -v 2.0.2
  3. Install MySQL gem (as of March 5, 2008, it is version 2.7.3) and add MySQL executable to path.
    gem install mysql
  4. Create prayer application.
    rails prayer -d mysql
  5. Install Restful Authentication plugin.
    cd prayer
    ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/
  6. Create scaffold for prayer model.
    ruby script/generate scaffold Prayer title:string body:text

    The first thing I noticed different about Rails 2.0 is that the scaffold now also generates the model and data migration file with title and body as columns in the prayer table. Also the format of the data migration file is slightly more compact.
  7. Create user model with authentication. The --include-activation flag is to create the mailers for activation and signup notification.
    ruby script/generate authenticated user sessions --include-activation
  8. Configure config/database.yml and then create prayer and user tables in DB.
    rake db:migrate
  9. Configure SMTP settings.
  10. Modify app/models/user_mailer.rb, replacing the place holders with constants which you can configure with different values for different environments using config/environments/development.rb, config/environments/production.rb.
  11. Modify user_observer.rb to incorporate the reset and forgotten password features.
  12. Create scaffold for role model. Add an admin user.
    ruby script/generate scaffold Role rolename:string
  13. Create permission model. Modify role and permission models to know about each other.
    ruby script/generate model Permission
  14. Modify user model to use permissions.

Much of this post is based on this excellent post, Restful Authentication with all the bells and whistles.  At this point I did not continue with much of the tutorial, especially with parts like password forgotten, separate account controller, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *