0

谁能解释为什么我在生产中不断出现错误,但在开发中却没有?相关部分:

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

我正在使用带有最新 Omniauth 的 Rails 3.2.3。

4

1 回答 1

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

阅读本文以获取有关命名空间和路由的更多文档。

于 2012-04-21T17:14:16.650 回答