[英]Rails redirection to custom action in devise subclassed sessions controller
my_devsie/sessions_controller.rb my_devsie / sessions_controller.rb
class MyDevise::SessionsController < Devise::SessionsController
def dash_board
end
end
application_controller.rb application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def after_sign_in_path_for(resource)
sign_in_url = url_for(:action => 'dash_board', :controller => '/my_devise/sessions', :only_path => false, :protocol => 'http')
if request.referer == sign_in_url
super
else
stored_location_for(resource) || request.referer || root_path
end
end
end
routes.rb 的routes.rb
devise_for :users, controllers: { registrations: "my_devise/registrations",
sessions: "my_devise/sessions" }
app structure 应用程式结构
app
---controller
------my_devise
---------sessoins_controller.rb
and the error is 错误是
ActionController::UrlGenerationError at /users/sign_in
No route matches {:action=>"dash_board", :controller=>"my_devise/sessions"}
I would like to redirect to "dash_board" method in my_devise/session_controller for displaying appropriate dashboard view after successfull login, sign-up and profile update 我想重定向到my_devise / session_controller中的“ dash_board”方法,以便在成功登录,注册和更新配置文件后显示适当的仪表板视图
The routes is not been found for the dash_board action. 找不到针对dash_board操作的路由。 You must add a route for it.
您必须为其添加一条路线。 Try below if it works.
如果可行,请尝试以下操作。
devise_scope :user do
get "my_dashboard" =>"my_devise/sessions#dash_board"
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.