Skip to content

Instantly share code, notes, and snippets.

@balinterdi
Created September 23, 2016 08:29
Show Gist options
  • Select an option

  • Save balinterdi/20ebdaf438a083efe7454ef6d2eda752 to your computer and use it in GitHub Desktop.

Select an option

Save balinterdi/20ebdaf438a083efe7454ef6d2eda752 to your computer and use it in GitHub Desktop.
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