Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

Unlocking the ‘Devise’ Gem | RailsCarma

Author: James Carma
by James Carma
Posted: Dec 22, 2015

If we have to don our wizarding hat and take out our crystal balls, we would still be harping that Ruby on Rails is going to be hot in 2016 too! 2016 is also going to bring in only 24 hours a day (how we wish, we could stretch the time) and time would still spell money for businesspeople. When time is money, anything which can save time is gold! And that’s where Ruby on Rails come in picture. What could take other programming languages months to complete, takes only weeks, sometimes just days for Ruby on Rails. Shaping ideas into applications was never so easy. With Ruby on Rails, agility is the norm and convention over configuration the benchmark. And what make Ruby on Rails more powerful are the bunch of pre-packaged, categorized, reusable codes, named as gems. With gems, Rails is a super power to behold. One of the most popular gems is called as Devise Gems, which is a complete authentication package. Read on to know more about Devise gem.

What is ‘Devise’ Gem?

  1. Devise is a powerful & flexible authentication solution for Rails.
  2. It is completely based on MVC structure.
  3. It allows to have multiple models signed in at the same time.

Different Modules of Devise

Devise is composed of 10 important modules.

  1. Database Authenticatable: It encrypts and stocks passwords in the database so that the validation could be done for the authenticity of a user at the time of signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
  2. Omniauthable: Add OmniAuth support i.e. possible to set up a login with OmniAuth.
  3. Confirmable: Sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
  4. Recoverable: Resets the user password and sends reset instructions.
  5. Registerable: Handles registration process by signing up users also allowing them to edit and destroy their account.
  6. Rememberable: As the name suggests, it helps in managing, generating and clearing a token for remembering the user through saved cookies.
  7. Trackable: Tracks sign in count, timestamps and IP address.
  8. Timeoutable: Expires sessions that have not been active in a specified period of time.
  9. Validatable: Provides validations of email and password. It’s optional and can be customized, so you’re able to define your own validations.
  10. Lockable: It helps in locking an account after a specific number of failed sign-in attempts. The account could be unlocked via email or after specific time period.

Install Devise, Create Model, View & Configure

  1. Create your rails app
  2. Add gem ‘devise’ to your Gemfile.
  3. Run bundle install in your command line.
  4. Execute rails generate devise:install in your command line.
  5. Execute rails generate devise in your command line to create model. Ex:- rails generate devise user. After running rails generate devise user, you should see a user.rb model in your models directory.class User


  6. For the current signed-in user => current_user
  7. access the session for this scope: => user_session
  8. You can also override after_sign_in_path_for and after_sign_out_path_for to customize your redirect paths.
  9. You can integrate ‘activeadmin’ gem, ‘devise_invitable’ gem with devises.

    When it comes to time saving, nothing beats Ruby on Rails. If you have an idea and would like to get it implemented, the best bet for you would be to go for Ruby on Rails. RailsCarma has been implementing Ruby on Rails from its nascent stages for development, training, deploying and contributing back to the Rails Community and provide best Ruby on Rails development services. RailsCarma provide end to end Ruby on Rails services including, consulting, architecture, building, management and extension to companies around the globe. You can also hire Ruby on Rails developers with an easy to hire process. Contact Us to know more.

    About the Author

    Visit our site to know more.

    Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Author: James Carma

James Carma

Member since: Nov 22, 2015
Published articles: 6

Related Articles