Wednesday, October 25, 2006

How to setup RESTful Authentication

The following steps are tested on Mac OS 10.4.8

1. Create the Rails application: rails testr

2. Cd to testr directory. You need Rails 1.2 for this plugin, so:
rake rails:freeze:edge

3. Install the plugin: ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/
(the command must be in one line)

4. Add the resouces in the config/routes.rb file (just below the first line):

map.resources :users, :sessions
map.signup '/signup', :controller => 'users', :action => 'new'
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'

I also commented out the last line (default Rails 1.1 style routing).

5. Generate the migrations: ./script/generate authenticated user sessions

6. Generate mailer: ./script/generate authenticated_mailer user

7. Run mysql server

8. Specify the database password in database.yml file in config directory

9. Create testr_development database (Use CocoaSQL, YourSQL, MySQL Query Browser or command line)

10. Cd to db/migrate directory and run: rake db:migrate

11. Start the webserver: $testr > ./script/server

12. Point the browser to http://localhost:3000/signup

13. View the output of the signup process in the server console, you will see SQL insert statement.

14. Check the user table to see the newly created record.

15. Go to http://localhost:3000/login and http://localhost:3000/logout and play with the application.

I am getting sqlsock error in RailsLive CD environment. It has MySQL server 5.0. My mac has MySQL server 4.0 and it does not have any problems.

No comments:

Post a Comment