1
votes

I am running Rails 5.1 with Devise 4.2.1.

I have configured Devise confirmable: class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable

I have set the routes: devise_for :users

I have generated views, and customized the sign up and confirmation.

I have also generated controllers, but not customized these, and don't refer to them in routes.

I have set authendicate user in my App Controller: class ApplicationController < ActionController::Base #Login user before_action :authenticate_user!

When a user signs up he is redirected to sign in and not to confirmations/new.html.erb

What am I doing wrong?

1
That is the correct behavior. confirmation/new is for re-sending confirmation mail and you don't need that page after sign up since signup process itself sends a confirmation email. That new page should be visited only when user clicks 'Resend confirmation email' link.Sajan
Hi @Sajan - is this correct behavior? It never tells the user that the e-mail needs to be confirmed. It just redirects to login, with the alert - "You need to sign in ..."Thomas Thejn

1 Answers

1
votes

Follow all steps properly mentioned in below link:

https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users

Modifying the User Model

First, add devise :confirmable to your models/user.rb file

Create a New Migration

Then, do the migration as:

rails g migration add_confirmable_to_devise

Will generate db/migrate/YYYYMMDDxxx_add_confirmable_to_devise.rb. Add the following to it in order to do the migration.

class AddConfirmableToDevise < ActiveRecord::Migration
# Note: You can't use change, as User.update_all will fail in the down migration
  def up
    add_column :users, :confirmation_token, :string
    add_column :users, :confirmed_at, :datetime
    add_column :users, :confirmation_sent_at, :datetime
    # add_column :users, :unconfirmed_email, :string # Only if using reconfirmable
    add_index :users, :confirmation_token, unique: true
    # User.reset_column_information # Need for some types of updates, but not for update_all.
    # To avoid a short time window between running the migration and updating all existing
    # users as confirmed, do the following
    execute("UPDATE users SET confirmed_at = NOW()")
    # All existing user accounts should be able to log in after this.
    # Remind: Rails using SQLite as default. And SQLite has no such function :NOW.
    # Use :date('now') instead of :NOW when using SQLite.
    # => execute("UPDATE users SET confirmed_at = date('now')")
    # Or => User.all.update_all confirmed_at: Time.now
  end

  def down
    remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at
    # remove_columns :users, :unconfirmed_email # Only if using reconfirmable
  end
end

You can also generate the corresponding Devise views if they have not yet been created:

rails generate devise:views users

Do the migration rake db:migrate

Restart the server.