Setup Devise in Rails
11 March 2022 (Updated 23 April 2022)
Install gem
./bin/bundle add devise
Run installer and follow instructions
./bin/rails g devise:install
Instructions are something like:
- Ensure
config.action_mailer.default_url_options
is set. - Ensure
root_url
is set inconfig/routes.rb
. - Ensure flash messages are included in your
application.html.erb
file. For example:<% if notice %> <p class="notice"><%= notice %></p> <% end %> <% if alert %> <p class="alert"><%= alert %></p> <% end %>
- (Optional) Copy devise views.
rails g devise:views
Generate Devise model and migration
Run:
./bin/rails g devise User
If required, add any further changes to the generated model and migration files.
Run migrations
./bin/rails db:migrate
(Optional) Configure devise in RSpec
See this post.
(Optional) Configure to work with turbo-rails
At the time of writing (02/02/2021), it seems like Devise forms with turbo-rails
unless you add the data-turbo=false
attribute to the <form>
. See this issue.
Sources
Tagged:
Rails tooling
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment