Rails 'APIController' is not a supported controller name

bydmm · May 14, 2014 · Last by bydmm replied at May 14, 2014 · 3303 hits
resources :api, controller: 'APIController'

以上的 APIController 由于有多个大写字母 就报错了, 但是我又不能忍受 ApiController 这么傻的名字,因为 API 本来就是缩写了。 怎么办?

那你只能换个星座了。

在 config/initializers/inflections.rb 中加入如下代码就可以了

ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym 'API'
end
You need to Sign in before reply, if you don't have an account, please Sign up first.