DEV Community

austinmei5
austinmei5

Posted on

Devise Tutorial

  1. Add Devise gem in Gemfile and configure the app according to the instructions in the terminal.

  2. (cont.) Add 'config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }' to the 'development.rb' file.

  3. Create the users model using: 'rails generate devise user username'. This is a simple model that only tracks a user's username and nothing else. More variables and their data types can be added if necessary.

  4. Update default values in the users migration file. Make sure default values are appropriate.

  5. Add indexes where appropriate in the migration file. Example: "add_index" :users, :username, unique: true".

  6. (cont.) The index above provides a database level constraint on uniqueness.

  7. Add case-insensitive column for username. Add 'enable_extension("citext")' to the top of change method in the migration file.

  8. (cont.) Change username and email columns in migration file to 't.citext' instead of 't.string'. This adds database level protection for case insensitivity.

  9. Once all default values, indexes, and case-insensitivities are updated, migrate the model with 'rails db:migrate'

MISC - if we at any point drop the database, we need to use 'rails db:create' to re-add the database since we are using Postgre.

Top comments (0)