Rails重定向到设计子类会话控制器中的自定义操作

时间:2014-10-01 11:58:17

标签: ruby-on-rails ruby

my_devsie / sessions_controller.rb

class MyDevise::SessionsController < Devise::SessionsController
    def dash_board  
    end
end

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

devise_for :users, controllers: { registrations: "my_devise/registrations",
                                sessions: "my_devise/sessions" }

app结构

app  
---controller  
------my_devise  
---------sessoins_controller.rb 

,错误是

ActionController::UrlGenerationError at /users/sign_in
No route matches {:action=>"dash_board", :controller=>"my_devise/sessions"}  

我想在my_devise / session_controller中重定向到“dash_board”方法,以便在成功登录,注册和个人资料更新后显示相应的信息中心视图

1 个答案:

答案 0 :(得分:1)

找不到dash_board操作的路由。您必须为其添加路线。如果有效,请尝试以下。

devise_scope :user do
    get "my_dashboard" =>"my_devise/sessions#dash_board"
end