Придумайте подтверждаемую электронную почту на Rails - PullRequest
0 голосов
/ 10 апреля 2019

Хотите добавить 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

1 Ответ

2 голосов
/ 10 апреля 2019

Можете ли вы попробовать изменить, как показано ниже:

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

замените en своим языком. Проверьте: ActionController :: UrlGenerationError в Devise :: Registrations # create

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...