Skip to content

Instantly share code, notes, and snippets.

@omgreenfield
Created September 3, 2016 07:15
Show Gist options
  • Save omgreenfield/d81749cef622a907b180f80bac848993 to your computer and use it in GitHub Desktop.
Save omgreenfield/d81749cef622a907b180f80bac848993 to your computer and use it in GitHub Desktop.
Devise - Quick setup for RoR Gem

Setting up Devise Rails Gem

Add gem to Gemfile

Add this line to your Gemfile:

gem 'devise'

Install Devise Files

From the terminal, run these commands:

bundle install
rails generate devise:install
rails generate devise user
rails generate devise:views

Make User Confirmable

Open user.rb and add ":confirmable" to the devise line.

Modify migration

Open the new migration file generated by devise and uncomment the lines under the "Confirmable" area

Set up outbound email

If you don't have an gmail account you want to use for sending emails, make one.

Then you can put this boiler plate code in development.rb:

development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method= :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = {host: 'localhost', port:3000}
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "gmail.com",
  authentication: "plain",
  enable_starttls_auto:true,
  user_name: "<username>",
  password: "<password>"
}

For username, just put the account part before the "@" symbol. If my email is "dude@gmail.com", I'll just put "dude" here.

Configure Mailer Sender

In config/initializers/devise.rb, change the "config.mailer_sender" item to the email account you used above. For example, "dude@gmail.com".

Creating a new account

You can check the routes that devise creates (by running rake routes from the command line). To create a new user, go to localhost:3000/users/sign_up

You'll have to put in an email address, a password of 6 characters or more, and confirm your password. Then check your email and you can confirm your account.

Using Devise

TBD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment