Using version 0.6.0
of the jsonapi-resources gem in conjuction with Doorkeeper I am having a problem seeing the current user in the context
object in my resource.
I am basically following the docs, however nothing I try will make the context
I set in ApplicationController
visible in the resource's fetchable_fields
method. I did confirm that context
is actually being set in my ApplicationController
.
Here is what I have
ApplicationController
class ApplicationController < JSONAPI::ResourceController
protect_from_forgery with: :null_session
def context
{current_user: current_user}
end
end
Controller
class Api::ItemsController < ApplicationController
prepend_before_action :doorkeeper_authorize!
end
Resource
class Api::ItemResource < JSONAPI::Resource
# attributes
def fetchable_fields
# context is always nil here
if (context[:current_user].guest)
super - [:field_i_want_private]
else
super
end
end
end