Created
September 23, 2016 08:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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