Failure/Error: render jsonapi: user, status: 201
Graphiti::Errors::InvalidLink:
UserResource: Cannot link to sideload :cards!
Make sure the endpoint "/api/v1/cards" exists with action :index, or customize the endpoint for CardResource.
If you do not wish to generate a link, pass link: false or set self.autolink = false.
My models:
class User < ApplicationRecord
has_many :cards
validates :email, uniqueness: true
end
class Card < ApplicationRecord
belongs_to :user
end
My resources:
class ApplicationResource < Graphiti::Resource
self.abstract_class = true
self.adapter = Graphiti::Adapters::ActiveRecord
self.base_url = Rails.application.routes.default_url_options[:host]
self.endpoint_namespace = '/api/v1'
end
class UserResource < ApplicationResource
attribute :email, :string
has_many :cards
end
class CardResource < ApplicationResource
attribute :bonuses, :integer
belongs_to :user
end
My routes.rb:
Rails.application.routes.draw do
scope path: ApplicationResource.endpoint_namespace do
resources :users, only: %i[show create update index]
resources :cards, only: %i[show index]
end
end
So action :index exists. What else do I need to do to fix this error?
Hello, I'm trying to use Graphiti.
I'm stuck with this error.
My models:
My resources:
My routes.rb:
So action :index exists. What else do I need to do to fix this error?