我正在尝试将命名空间添加到我的“类别” Controller 和资源中。
所以我做的第一件事就是将 categories_controller.rb
移动到 app/controllers/api/v1/categories_controller
和 category_resource.rb
到 app/resources/api/v1/
然后我重新声明这些工件如下:
Controller
module Api
module V1
class CategoriesController < ApplicationController
#before_action :doorkeeper_authorize!
end
end
end
资源
module Api
module V1
class CategoryResource < JSONAPI::Resource
attribute :name
end
end
end
在 routes.rb
中,我将类别路由移到了
namespace :api do
namespace :v1 do
jsonapi_resources :categories
end
end
我在尝试解决这个问题时遇到了不同的错误。对于当前配置,这是我得到的错误:
JSONAPI: Could not find resource 'categories'. (Class CategoryResource not found) (NameError)
我做错了什么?
最佳答案
根据此处的文档 (https://github.com/cerebris/jsonapi-resources),您不应移动该资源。
而且它不应该在模块中。
关于ruby-on-rails - 命名空间 JSONAPI 资源和 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37246580/