User management for ruby on rails.

Photo by UX Indonesia on Unsplash

This week I want to talk about Devise for Ruby on rails. These past few weeks i’ve been diving back into Rails and I discovered an amazing authentication tool that is just so mind blowingly easy to use that my projects are now going to get done so much faster.

In this post I’m just going to go through the initial setup of Devise so that you can add it to your existing project and continue on your own.

So with that being said let's get started.

Devise is a gem for user management and with a few simple steps can be completely setup and integrated seamlessly into your project.

So first we can visit https://rubygems.org/ which is a wonderful resource for all ruby gems. Once you’re there just type devise into the searchbar and you will see it has over 96 million downloads, just click on that and you will see on the right hand side the gemfile or the install option, we’re going to use the germfile option.

so just click copy on that and headover to your code open your Gemfile and just paste it in there.

Now that it’s in your Gemfile you will need to go to your terminal and run bundle install to install the new gem (anytime you add a new gem you need to run bundle install from your terminal).

Our next step is to go back to that website https://rubygems.org/ and click on the documentation link on the right hand side.

or click here and you will be brought to the devise github page which. has more detail on how to finish this install. Feel free to read this and give it a go yourself or read for a more precise step by step.

So next, let’s head back to our terminal and run

rails generate devise:install

This will now give you more install instructions in your terminal, some of which we have already done.

Read the instructions carefully and paste in the code where it tells you what file to do this in Keep in mind that when it talks about deployment code you can paste it in but just comment it out till you’re ready to deploy.

typically the last step is to copy devise views with this command

rails g devise:views

this will give you all the devise views in the app/views/devise folder.

Okay, now after following the terminal instructions we can go back to our devise github page and see whats next.

Next we will need to go back to the terminal and run

rails generate devise model

where model is you can name it what you like, I named mine user because this is typically for the user.

So you will notice that a migration has been created along with some other stuff

As you know after a migration has been created you need to run

rails db:migrate

to push it. Now that it’s all installed properly you can read the helper methods and incorporate them into your project.

So that’s pretty much it. I love Devise because it’s saves me so so much time developing and it works amazingly.

As always thank you for reading!

Learning to code, one day at a time.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store