Rails命名空间路由在开发中工作但不在生产中工作

doc*_*nge 5 routes namespaces ruby-on-rails production-environment

我正在尝试在名称空间帐户下嵌套一些路由.

我希望帐户下的用户管理/account/users/account/users/5/edit

在routes.rb中:

namespace :account do
  resources :users do
    member do
      put 'generate_api_key'
    end 

    collection do
      post 'api_key'
    end 
  end 
end 
Run Code Online (Sandbox Code Playgroud)

我的控制器没有命名空间或将它们放在任何不同的目录中.

/app
  /controllers
    accounts_controller.rb
    users_controller.rb
Run Code Online (Sandbox Code Playgroud)

在我的开发环境,这是工作正常,但在生产中,我得到404个响应任何的/account/users...路径(其中,顺便说一句,都仍然正确生成:new_account_users_path,edit_account_user_path,等).

rake routes在两个环境中生成相同的输出.这是相关的一点:

 generate_api_key_account_user PUT    /account/users/:id/generate_api_key(.:format)                      {:action=>"generate_api_key", :controller=>"account/users"}
         api_key_account_users POST   /account/users/api_key(.:format)                                   {:action=>"api_key", :controller=>"account/users"}
                 account_users GET    /account/users(.:format)                                           {:action=>"index", :controller=>"account/users"}
                               POST   /account/users(.:format)                                           {:action=>"create", :controller=>"account/users"}
              new_account_user GET    /account/users/new(.:format)                                       {:action=>"new", :controller=>"account/users"}
             edit_account_user GET    /account/users/:id/edit(.:format)                                  {:action=>"edit", :controller=>"account/users"}
                  account_user GET    /account/users/:id(.:format)                                       {:action=>"show", :controller=>"account/users"}
                               PUT    /account/users/:id(.:format)                                       {:action=>"update", :controller=>"account/users"}
                               DELETE /account/users/:id(.:format)                                       {:action=>"destroy", :controller=>"account/users"}
Run Code Online (Sandbox Code Playgroud)

鉴于路由似乎Users/account子目录中寻找控制器,我想我的问题是为什么这在开发中工作?

生产是:

  • Rails 3.0.7
  • 乘客
  • 阿帕奇

发展是:

  • Rails 3.0.7
  • 杂种

感谢您对此的看法.

Rya*_*igg 5

如果你是这样的命名空间,Rails要求控制器处于正确的路径,例如app/controllers/account/users_controller.rb.如果您不想这样做,请scope改用:

scope :path => "account" do
  resources :users
end
Run Code Online (Sandbox Code Playgroud)

  • 问题是,在开发过程中,如果没有在正确路径中正确命名的控制器,它实际上将在主路径中使用控制器.有点令人困惑. (2认同)