2012-04-21 54 views
0

任何人都可以解释为什么我一直在生产中出现错误,但不在开发中?相关部分:Rails:生产中的操作错误,但没有在开发中

get: /user/logout 
ActionController::RoutingError (uninitialized constant User::SessionController): 
    activesupport/lib/active_support/inflector/methods.rb:229:in `block in constantize' 
    activesupport/lib/active_support/inflector/methods.rb:228:in `each' 
    activesupport/lib/active_support/inflector/methods.rb:228:in `constantize' 
    actionpack/lib/action_dispatch/routing/route_set.rb:69:in `controller_reference' 
    actionpack/lib/action_dispatch/routing/route_set.rb:54:in `controller' 
    actionpack/lib/action_dispatch/routing/route_set.rb:32:in `call' 
    journey/lib/journey/router.rb:68:in `block in call' 
    journey/lib/journey/router.rb:56:in `each' 
    journey/lib/journey/router.rb:56:in `call' 
    actionpack/lib/action_dispatch/routing /route_set.rb:600:in `call' 
    omniauth/lib/omniauth/strategy.rb:177:in `call!' 
    omniauth/lib/omniauth/strategy.rb:157:in `call' 
    omniauth/lib/omniauth/builder.rb:48:in `call' 
    airbrake/lib/airbrake/rack.rb:27:in `call' 

路线:

Application1::Application.routes.draw do 
    match('/auth/:provider/callback' => 'session#create', :format => false) 
    root(:to => 'blog/archives#index', :format => false) 

    namespace(:user) do 
    match('/logout' => 'session#destroy', :format => false) 
    end 

    namespace(:blog) do 
    match('/archive/:slug' => 'archive#show', :format => false) 
    constraints(:page => /page\d+/) do 
     match('/archives/:page' => 'archives#index', :format => false) 
    end 
    end 
end 

我使用Rails 3.2.3最新Omniauth。

回答

0

您已经创建了一个命名空间用户,因此,你应该把会议控制器定义摧毁此路径行动:

/app/controllers/user/session_controller.rb 

然后,你可以做的东西,如:

/app/controller/user/base_controller.rb中创建一个文件,该文件对此进行了定义:

class User::BaseController < ApplicationController 
# Whatever you want here 
end 

,并确定位于/app/controllers/user/session_controller.rb作为会话控制器:

class Users::SessionsController < User::BaseController 
def destroy 
    # whatever you want destroy to do.. 
end 
end 

阅读this关于命名空间和路由的详细文档。

+0

会话是一个自己的控制器,公共接口是/ usr/logout => session#destroy和/ auth /去会话#创建。我不希望将一个共同的(共享的)控制器分成更难以管理的部分。我可以直接将它与session#destroy在namspace外部进行匹配,但是它内部预计你的状态,这是我不希望的,因为这意味着当我在/ user /的其余部分添加完成时,我在/ user中有一条路由命名空间之外。另外你指出的文档非常广泛,留下了很多需要解释的内容:命名空间和我的问题。 – 2012-04-21 17:30:40

相关问题