Rails命名空间控制器未初始化的常量错误

时间:2016-08-31 19:00:35

标签: ruby-on-rails

类似于this问题,但那里的答案不起作用。

routes.rb

scope '/api/ do
  namespace :v1 do
    scope :reports do
      get '/reportXYZ', to: 'reports#reportXYZ'
    end
  end
end

app/controllers/V1/reports_controller.rb

module V1
    class ReportsController < ApplicationController
      def reportXYZ
        ...
      end
    end
end

错误:

仅限Windows上的

uninitialized constant V1,在ubuntu上运行正常。怎么样?

1 个答案:

答案 0 :(得分:0)

In your routes .rb file instead of writing scope for api write like this

namespace :api do

  namespace :v1 do

    scope :reports do
      get '/reportXYZ', to: 'reports#reportXYZ
    end
  end

end

And in your controller

module api

  module V1

    class ReportsController < ApplicationController
      def reportXYZ
        ...
      end
    end

  end
END