ruby-on-rails – Rails命名空间路由在开发中工作但不在生产中工
发布时间:2020-12-17 03:12:58 所属栏目:百科 来源:网络整理
导读:我正在尝试在名称空间帐户下嵌套一些路由. 我想要帐户下的用户管理,如/ 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' en
我正在尝试在名称空间帐户下嵌套一些路由.
我想要帐户下的用户管理,如/ 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 我的控制器没有命名空间或将它们放在任何不同的目录中. /app /controllers accounts_controller.rb users_controller.rb 在我的开发环境中,这工作正常,但在生产中我得到404响应任何/ account / users …路径(顺便说一下,它们仍然正确生成:new_account_users_path,edit_account_user_path等). rake路由在两种环境中生成相同的输出.这是相关的一点: 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"} 鉴于路由似乎在/ account子目录中寻找Users控制器,我想我的问题是为什么这在开发中有效? 生产是: > Rails 3.0.7 发展是: > Rails 3.0.7 感谢您对此的看法. 解决方法
如果你是这样的命名空间,Rails要求控制器处于正确的路径,例如app / controllers / account / users_controller.rb.如果您不想这样做,那么请使用范围:
scope :path => "account" do resources :users end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |