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处于活动状态时似乎没有被调用.
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)
我一直在努力解决这个问题,直到意识到我已经忘记宣布我已经超越了设计注册控制器.就我而言,我正在使用:用户资源设计,所以我将其添加到routes.rb:
devise_for :users, :controllers => {:registrations => "registrations"}
Run Code Online (Sandbox Code Playgroud)
之后,我在after_inactive_sign_up_path_for中指定的重定向工作.
覆盖设计注册控制器有关于此主题的更完整的讨论,以及声明覆盖的替代方法.
您是否通过执行检查了show_cities_path是否存在rake routes?可能值得一看https://github.com/plataformatec/devise/wiki/How-To:-Change-the-redirect-path-after-destroying-a-session-ie-signing-out
| 归档时间: |
|
| 查看次数: |
18897 次 |
| 最近记录: |