Login with Devise
Set Up Devise
Follow these steps to configure Devise for user authentication in your Lightning Rails application.
Configure Devise
Open the production.rb file at config/environments/production.rb
and customize the host domain to match your production domain.
Configure email address for Devise::Mailer
(Optional): Further Customization of Devise
To customize the User model by adding additional fields like first_name
and last_name
, follow these steps:
Generate a Migration
Generate a migration to add the new fields to your User model:
Migrate the Database
Run the migration to update the database schema:
Permit Additional Parameters
To allow these new fields during sign-up and account update, you need to update the Devise parameters. Open or create the app/controllers/application_controller.rb
file and add the following code:
Update Views (Optional)
If you want users to input these additional fields during sign up and account editing, you must update the Devise views. Edit the app/views/devise/registrations/new.html.erb
and app/views/devise/registrations/edit.html.erb
files to include the new fields:
This will allow users to provide their first and last names when they sign up or update their account information.
Freeing a Page from Authentication
To allow access to a specific action without requiring user authentication, you can use the following code in the corresponding controller:
Make sure to change "action_name" to your new action name and "YourControllerName" to your new or existing controller name.
Additional Resources
For more information and advanced configurations, we invite you to check out the official Devise repository on GitHub:
If you care about your users, consider setting up magi links instead of passwords 😉 See the next feature: Magic Links
Last updated
Was this helpful?