2

I tried to namespace my resources and controllers, but now when I try to run my server it keeps getting this error:

JSONAPI: Could not find resource 'categories'. (Class CategoryResource not found)

controller/api/v1/categories_controller.rb

class Api::V1::CategoriesController < ApplicationController
end

resources/api/v1/category_resource.rb

class Api::V1::CategoryResource < JSONAPI::Resource
    attribute :name
    has_many :posts
end

I don't know what is triggering this error. I even removed the files and the reference to Category from the routes.rb

routes.rb

namespace :api do
    namespace :v1 do
      jsonapi_resources :categories
    end
  end

This started after I moved the files from the root of controllers and resources to api/v1. What is wrong with my project?

Victor Ferreira
  • 6,151
  • 13
  • 64
  • 120

1 Answers1

1

For your CategoriesController, try inheriting from JSONAPI::ResourceController instead of ApplicationController.

class Api::V1::CategoriesController < JSONAPI::ResourceController
jeffdill2
  • 3,968
  • 2
  • 30
  • 47