我们有一个rails应用程序,我们有一个API命名空间定义为API::V1, API::V1_2, API::V1_3等。
在路线。Rb,我们已经设置了以下
namespace :api do
["v1", "v1.2", "v1.3", "latest"].each do |name|
namespace name, {:module => name.gsub(".","__"), :as => name.gsub(".","_") } do
constraints :format => /json/ do
# user scoped views
resources :some_endpoint, :only => [:create, :index, :show, :update, :delete], :path => "scheduler" do
member do
put 'edit'
post 'duplicate'
end
end
end
end
end
在Rails 3.1下运行时可以正常工作,但是在Rails 3.2中我们得到一个路由错误:
[INFO pid: 17025: 14-07-28 19:06:15 ] Started GET "/api/v1.2/commands/1" for 192.168.1.130 at Mon Jul 28 19:06:15 -0700 2014
[FATAL pid: 17025: 14-07-28 19:06:15 ]
ActionController::RoutingError (uninitialized constant Api::V12):
activesupport (3.2.17) lib/active_support/inflector/methods.rb:219:in `constantize'
activesupport (3.2.17) lib/active_support/inflector/methods.rb:218:in `each'
activesupport (3.2.17) lib/active_support/inflector/methods.rb:218:in `constantize'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:69:in `controller_reference'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:54:in `controller'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:32:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.17) lib/action_dispatch/routing/route_set.rb:608:in `call'
omniauth (1.1.1) lib/omniauth/strategy.rb:177:in `call!'
omniauth (1.1.1) lib/omniauth/strategy.rb:157:in `call'
sass (3.2.6) lib/sass/./sass/plugin/rack.rb:54:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.17) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
当我们在rails 3.1上运行它时,上面的代码转换为Api:: v12。
任何想法可能是错误在这里,我如何修复它?代码在所有其他情况下都可以正常工作,包括渲染资产等。只有在这种情况下,rails才会抛出错误
曾经遇到过同样的事情。他们的github问题列表中有这个bug
https://github.com/rails/rails/issues/5849然后一个pull request
https://github.com/rails/rails/pull/6105 但是讨论没有达成任何解决方案。常见的语句是不喜欢模块中的uncores
所以你需要从模块名中去掉下划线