我在路线中有这个:
Rails.application.routes.draw do
namespace :api do
namespace :v3_4 do
# .....
和控制器app/controllers/api/v3_4/base_controller
module Api
module V3_4
class BaseController < ApplicationController
# ......
end
end
end
And app/controllers/api/v3_4/another_controller
module Api
module V3_4
class AnotherController < ApplicationController
end
end
end
耙子路线:
Prefix Verb URI Pattern Controller#Action
api_v3_4_test GET /api/v3_4/test(.:format) api/v3_4/base#test
api_v3_4_one GET|OPTIONS /api/v3_4/one(.:format) api/v3_4/another#one
api_v3_4 GET|OPTIONS /api/v3_4/two/:id(.:format) api/v3_4/another#two
然而对于这个请求我得到Routing Error Uninit Constant uninitialized constant Api::V34
请注意,错误消息中没有下划线。
但我的项目根本没有V34线,也没有v34,只有v3_4和V3_4
铁轨活用_
作为单词分隔符,因此它会搜索 Api::V34 您可以通过编辑来更改该行为config/initializers/inflections.rb
:
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'V3_4'
end
另外,如果你想改变Api
命名空间到API
,因为它是一个缩写词,你也可以在那里做:
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'V3_4'
inflect.acronym 'API'
end
更多信息:http://api.rubyonrails.org/classes/ActiveSupport/Inflector/Inflections.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)