Devise is a Rails gem which could help you managing the authentication of your Rails project.
This post followed the steps in Railscasts – Introducing Devise. I made my own notes here such that i don’t need to watch the tutorial again. It is highly recommended to go through the video.
1. Create a new empty project.
- rails new <devise_trial>
2. Add the following line in Gemfile to include the Devise gem.
- gem ‘devise’
3. Install the newly added gems
- bundle install
4. Generate the Devise files
- rails g devise:install
5. Add the config.action_mailer.default_url_options in <project_root>/config/environments/development.rb.
...
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Add the config.action_mailer.default_url_options
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
6. Generate the Authentication model which is User in this example.
- rails g devise User
7. Migrate the database. A users table is created.
- rake db:migrate
8. Add the root route in <project_root>/config/routes.rb
... # The following line is created by Devise automatically devise_for :users # Let's add the root route root :to => "home#index" ...
9. Check the routes by the rake routes command. There should be a list of /users… routes as depicted as follow.

10. Start your application by rails s and register a new account @ http://localhost:3000/users/sign_up.
11. Open rails console and input User.first to check your newly registered account
Done =)
Reference:

worked perfectly! other solutions had all kinds of workarounds to get it working, this was nice & straight forward.
LikeLike
you are welcome =)
LikeLike
Wow, thx. That was the fastest devise setup ever 🙂 Thx!!
LikeLike
This post is just based on the video tutorial in Railscasts
Good to know that it could help you =)
LikeLike
Typo on step 5: localhost (not locathost)
LikeLike
updated, thx =)
LikeLike
Very simple to follow. I got this up and running on my local host within minutes.
I was actually looking for some help. I want to run this on Heroku and I figured changing the host in config/environments/development.rb would work if it was i.e: http://my-heroku-app.com but after i deployed my heroku after updating my gemfile as well as running heroku rake db:migrate, all my models were created but the problem is:
going to http://my-heorku-app.com/users/sign_up wouldn’t show up. any suggestions? Thank you.
LikeLike
Actually I got it to work. looked through heroku logs and found the error related to a css file not being precompiled.
LikeLike
Good to know that you have solved the problem~ =D
LikeLike
This is a fantastic solution! It worked perfectly. Would you happen to have example for setting up mulitiple models to use one form?
LikeLike
Hope the following examples could help you.
LikeLike