【问题标题】:how to redirect to refinery dashboard page instead of application root to page如何重定向到炼油厂仪表板页面而不是应用程序根到页面
【发布时间】:2012-10-08 12:32:41
【问题描述】:
我有一个使用 devise 2.0.0 进行身份验证的 rails 3.2.8 应用程序我将 reinerycms 与此应用程序集成,它现在已成功集成,问题是用户点击时
localhost/refinery 它带我进入炼油厂登录页面,但之后
成功登录它会重定向回我的应用程序主页而不是
比炼油厂的仪表板页面。
所以我想知道如何重定向到
炼油厂成功登录程序后的炼油厂仪表板。
我有路由挂载Refinery::Core::Engine,
:at => '/' root to:'projects#index'
等
【问题讨论】:
标签:
ruby-on-rails
ruby-on-rails-3.2
refinerycms
【解决方案1】:
创建一个自定义设计控制器,在用户登录后将其重定向到您想要的位置:
创建自定义控制器:controllers/users/sessions_controller.rb
class Users::SessionsController < Devise::SessionsController
before_filter :authenticate_user!, :only => [:destroy]
def new
super
end
def create
#Can edit this for custom redirect
super
end
def destroy
super
end
protected
def stub_options(resource)
methods = resource_class.authentication_keys.dup
methods = methods.keys if methods.is_a?(Hash)
methods << :password if resource.respond_to?(:password)
{ :methods => methods, :only => [:password] }
end
def after_sign_in_path_for(resource)
#Can edit this for custom redirect
super
end
def after_sign_out_path_for(resource)
super
end
private
end
然后告诉 devise 在你的 routes.rb 中使用该控制器:
devise_for :users, :controllers => {:sessions => "users/sessions"}