Locked lesson.
About this lesson
Allow people to sign up to your site, log in, and log out. Part 1.
Exercise files
Download this lesson’s related exercise files.
Devise Installation Part 1.docx58.6 KB Devise Installation Part 1 - Solution.docx
58.9 KB
Quick reference
Devise Installation Part 1
In this video we'll begin to install Devise to handle user management.
When to use
Devise is a great Ruby Gem that handles User Management. It allows people to sign up for your site, sign in, update their profile, and more.
Instructions
Head to RubyGems.org and search for "Devise".
Copy the gem reference to your Gemfile, save the file, and then run the "Bundle Install" command in the terminal.
Be sure to read the Devise documentation at RubyGems.org as well as the instructions that appear in your terminal after running the next command.
Next: run this command in the terminal:
rails generate devise:install
Next: in your config/environments/development.rb file, add this line of code:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
Next: in your config/environments/production.rb file, add this line of code:
config.action_mailer.default_url_options = { host: 'yourappname.herokuapp.com'}
Be sure to change the "yourappname.herokuapp.com" url to your actual heroku url.
Next: Add a partial file named _flashmessage.html.erb to your app/views/home directory and add this code:
<% flash.each do |name, msg| %>
<div class="alert alert-warning alert-dismissible">
<button class="close" data-dismiss="alert">
<i class="glyphicon glyphicon-remove-circle"></i>
</button>
<%= content_tag(:div, msg) %>
</div>
<% end %>
Next: Render your partial right above the yield tag on your app/views/layouts/application.html.erb file:
<%= render 'home/flashmessage' %>
Next: enter this command into your terminal to render Devise views:
rails g devise:views
That's it for this video!
Hints & tips
- Step 1: Add the Devise Gem to your Gemfile and then run Bundle Install
- Step 2: Run this command in your terminal rails generate devise:install
- Step 3: Modify your config/environments/development.rb file
- Step 4: Modify your config/environments/production.rb
- Step 5: Ccreate a partial and add your flash message code to it
- Step 6: Add your partial render code to your application.html.erb file
- Step 7: Run this command in your terminal rails g devise:views
Lesson notes are only available for subscribers.