I am learning how to code on the Rails framework. I just discovered Devise today, and listened to the Railscast. The sample code that comes with the Railscast works on Rails 2, so I re-built it to work on Rails 3. You can download the code in a TAR-GZ archive.
If you don’t already have a site you want to integrate this into, then just uncompress, run ‘bundle install’, and start your server! The devise installation is already done and was used to create a model called ‘User’.
If you are trying to find the changes you have to make to enable devise, here’s what you have to do:
- In your Gemfile, add gem ‘devise’
- bundle install, of course.
- Copy out the configuration details from the config/environments/development.rb file (the email address that sends account-related emails, for example.)
- Copy the devise.rb file from config/initializers. You get this step for “free” if you use the rails g devise:install command as well.
- These two steps are specific to adding the model that will hold the authorization information – in this case, the name of the model is user. You can also do this by running the Rails task rails generate devise user.
- To your routes.rb file, add the line devise_for :users
- Add the user.rb file to the models folder
- Add the migration for the user model and run rake db:migrate