希望将Confirmable添加到基于设计的应用程序中。我做了所有必要的修改,并收到以下错误:
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'
我想补充些什么? 路线:
devise_for :users, controllers: {registrations: "registrations", confirmations: "confirmations"}
最后一次迁移:
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
甚至添加了确认控制器:
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
答案 0 :(得分:2)
您可以尝试如下修改:
<p><%= link_to _('Confirm my account'), confirmation_url(@resource, confirmation_token: @token, locale: 'en') %></p>
用您的语言环境替换 验证:ActionController::UrlGenerationError in Devise::Registrations#create