Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some non-working ways to use jsonapi_resources primitives to craft a response
class SongsController < ApplicationController
def index
# params[:bandId], params[:q]
serializer = JSONAPI::ResourceSerializer.new(SongResource)
resource = SongResource.new(song, context)
render json: serializer.serialize_to_hash(resource)
end
def index
songs = Band.find(params[:bandId]).songs.where("title LIKE '%#{params[:q]}%'")
song_resources = songs.map { |song| SongResource.new(song, context) }
operation_result = JSONAPI::ResourcesOperationResult.new(:ok, song_resources)
render_results(operation_result)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.