[RUBY] Problem of not being able to db: migrate when adding Sorcery submodules

When creating an authentication function with Sorcery, I install a submodule every time I add each function, but I stumbled at the beginning trying to proceed according to the official tutorial, so I will describe the solution.

Until you hit the problem

Let's take the example of adding the User Activation function.

First, install the submodule

$ rails g sorcery:install user_activation  --only-submodules

Then the following migration file will be created.

[timestamp]_sorcery_user_activation.rb


class SorceryUserActivation < ActiveRecord::Migration
  def change
    add_column :users, :activation_state, :string, :default => nil
    add_column :users, :activation_token, :string, :default => nil
    add_column :users, :activation_token_expires_at, :datetime, :default => nil

    add_index :users, :activation_token
  end

end

And my great

$ rails db:migrate

An error occurred here!

rails aborted!
ArgumentError: To use user_activation submodule, you must define a mailer (config.user_activation_mailer = YourMailerClass).

The error message says "If you use this submodule, write a mailer!", But when I follow it, another error occurs and I can't proceed.

Cause

This problem occurs when you first type the command to add a submodule, and it is automatically added to the part that you should add later.

config/initializers/sorcery.rb


Rails.application.config.sorcery.submodules = [:user_activation, :Other submodules...]

If you proceed according to the tutorial, you will be instructed to add the above : user_activation later, but if this is described now, you will not be able to proceed, so delete it once.

config/initializers/sorcery.rb


Rails.application.config.sorcery.submodules = [(:Other submodules)...]

Finally I can migrate.

$ rails db:migrate

After that, if you proceed according to the tutorial, there is an instruction to add : user_activation, so add it there and solve it.

reference

Sorcery/wiki/User-Activation

Recommended Posts

Problem of not being able to db: migrate when adding Sorcery submodules
[Rails] The cause of not being able to post was in form_with