如何在Rails中更改confirmation_url

时间:2016-07-07 06:56:04

标签: ruby-on-rails devise

设计发送邮件指令以进行帐户确认。当用户点击“确认”链接时,他们的帐户会被激活,用户会被重定向到static_pages#home页面,但我需要将此链接重定向到其他页面。

确认网址:

<p><%= link_to 'Подтвердить мой аккаунт', confirmation_url(@resource, confirmation_token: @token) %></p>

confirmation_controller:

class Users::ConfirmationsController < Devise::ConfirmationsController
  # GET /resource/confirmation/new
   def new
     super
   end

  # POST /resource/confirmation
   def create
     super
   end

  # GET /resource/confirmation?confirmation_token=abcdef
   def show
     super
   end

   protected

  # The path used after resending confirmation instructions.
   def after_resending_confirmation_instructions_path_for(resource_name)
     super(resource_name)
   end

  # The path used after confirmation.
   def after_confirmation_path_for(resource_name, resource)
     new_profiles_path (resource_name, resource)
   end

end

浏览器中的新错误:

  

/home/vlad/Desktop/MyApp/app/controllers/users/confirmations_controller.rb:26:   语法错误,意外',',期待')'new_profiles_path   (resource_name,resource)^

1 个答案:

答案 0 :(得分:0)

您无需更改confirmation_url,而是需要覆盖after_confirmation_path_for

为此,您需要在after_confirmation_path_for

中定义ConfirmationsController

为此,请在confirmations_controller.rb目录中创建app/controllers

class ConfirmationsController     < Devise::ConfirmationsController

  private

  def     after_confirmation_path_for(resource_name, resource)
        your_new_after_confirmation_path
  end

end

config/routes.rb中,添加此行,以便Devise将使用您的自定义ConfirmationsController。

devise_for :users, controllers: { confirmations: 'confirmations' }

重新启动网络服务器,你应该拥有它。

请参阅Devise Wiki了解更多选项/详情

<强>更新

以下是confirmations_controller.rb

class Users::ConfirmationsController < Devise::ConfirmationsController
# GET /resource/confirmation/new
def new
 super
end
# POST /resource/confirmation
def create
  super
end

# GET /resource/confirmation?confirmation_token=abcdef
def show
 super
end

protected # The path used after resending confirmation instructions.
def after_resending_confirmation_instructions_path_for(resource_name)
 super(resource_name)
end

# The path used after confirmation.
def after_confirmation_path_for(resource_name, resource)
 new_profiles_path(resource_name, resource)
end
end