覆盖设计after_sign_up_path_for不起作用

kat*_*tie 23 ruby-on-rails devise ruby-on-rails-3 ruby-on-rails-3.1

在路由中我有根路径指向"home#index"但当我尝试覆盖它时,after_sign_up_path_for在我登录或注册时保持将我重定向到根路径.我试图将它放在设计子类控制器和application_controller中,但它不起作用.我需要做什么?

应用控制器

class ApplicationController < ActionController::Base
  protect_from_forgery

  def after_sign_up_path_for(resource)
    show_cities_path(resource)
  end
end
Run Code Online (Sandbox Code Playgroud)

登记控制员

class RegistrationsController < ApplicationController
  def after_sign_up_path_for(resource)
    show_cities_path(resource)
  end
end
Run Code Online (Sandbox Code Playgroud)

路线

root :to => "home#index"
Run Code Online (Sandbox Code Playgroud)

Rya*_*aig 80

如果您还启用了可确认模块,则必须覆盖,after_inactive_sign_up_path_for因为新注册处于"非活动状态",直到确认为止.after_sign_up_path_for当Confirmable处于活动状态时似乎没有被调用.

  • 事实上,在当前的时间点,你必须注意,该方法不会被`ApplicationController`中类似命名的方法覆盖 - 你必须为`:registrations`声明你自己的控制器,你需要它插入这个唯一的方法(`after_inactive_sign_up_path_for`). (2认同)

Rya*_*cis 14

虽然我迟到了比赛,但我遇到了这个问题并且无法找到解决方案.

如果您使用自己的RegistrationsController来自定义Devise,那么您需要将after_sign_up_path_for(resource)方法添加到该控制器而不是ApplicationController.

在registrations_controller.rb中:

private

  def after_sign_up_path_for(resource)
    new_page_path
  end
Run Code Online (Sandbox Code Playgroud)

https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb


And*_* R. 7

我一直在努力解决这个问题,直到意识到我已经忘记宣布我已经超越了设计注册控制器.就我而言,我正在使用:用户资源设计,所以我将其添加到routes.rb:

devise_for :users, :controllers => {:registrations => "registrations"}
Run Code Online (Sandbox Code Playgroud)

之后,我在after_inactive_sign_up_path_for中指定的重定向工作.

覆盖设计注册控制器有关于此主题的更完整的讨论,以及声明覆盖的替代方法.


Ell*_*iot 6

您是否通过执行检查了show_cities_path是否存在rake routes?可能值得一看https://github.com/plataformatec/devise/wiki/How-To:-Change-the-redirect-path-after-destroying-a-session-ie-signing-out