简体   繁体   中英

Devise reconfirmable email on Rails

Looking to add Confirmable to my devise-based app. I did all the require modification and get the following error:

Devise::Mailer#confirmation_instructions: processed outbound mail in 396.6ms
Completed 500 Internal Server Error in 1121ms (Searchkick: 363.9ms | ActiveRecord: 79.5ms)



ActionView::Template::Error (No route matches {:action=>"show", :confirmation_token=>"zWERAUmo5t5EFCM_oozY", :controller=>"confirmations"}, missing required keys: [:locale]):
    2: 
    3: <p>You can confirm your account email through the link below:</p>
    4: 
    5: <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

app/views/devise/mailer/confirmation_instructions.html.erb:5:in `_app_views_devise_mailer_confirmation_instructions_html_erb___2447835981562066598_70317651481800'

What am I suppose to add please ? Routes:

devise_for :users, controllers: {registrations: "registrations", confirmations: "confirmations"}

Last migration:

class AddConfirmableToDevise < ActiveRecord::Migration[5.1]
# 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
    User.update_all confirmed_at: DateTime.now
    # All existing user accounts should be able to log in after this.
  end

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

Even added a confirmation controller:

class ConfirmationsController < Devise::ConfirmationsController
  private
  def after_confirmation_path_for(resource_name, resource)
    #sign_in(resource) # In case you want to sign in the user
    new_session_path(resource_name)
  end
end

Can you try modifying as below :

<p><%= link_to _('Confirm my account'), confirmation_url(@resource, confirmation_token: @token, locale: 'en') %></p>

replace en with your locale Verify : ActionController::UrlGenerationError in Devise::Registrations#create

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM