Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling fields option to json adapter #999

Conversation

joaomdmoura
Copy link
Member

It fix #992

fields option was used on Json API adapter but never on Json adapter. This implements the fields option on it.

It enables you to filter the fields you want on render method call:

class ProfileSerialization < ActiveModel::Serializer
  attributes :name, :description

  has_many :friends
end
# ProfileController

# Define the resource fields you want in the response
def show
  @profile = Profile.find(params[:id)
   render json: profile, fields: [:name]
end

# You can also define the resource relationships fields you want in the response
def show_with_some_relationship_data
  @profile = Profile.find(params[:id)
   render json: profile, fields: {profile: [:name], friends: [:id]}
end

@joaomdmoura joaomdmoura self-assigned this Jul 10, 2015
@joaomdmoura joaomdmoura added this to the 0.10 milestone Jul 10, 2015
@joaomdmoura joaomdmoura force-pushed the enabling-fields-option-to-json-adapter branch from 11169eb to c559052 Compare July 23, 2015 06:19
@joaomdmoura
Copy link
Member Author

Rebased with master, now with root as class name, tests are supposed to be okay! 😄

@joaomdmoura joaomdmoura force-pushed the enabling-fields-option-to-json-adapter branch from 21352c0 to 53d5915 Compare August 17, 2015 06:41
@joaomdmoura joaomdmoura removed this from the 0.10 milestone Aug 17, 2015
@bf4
Copy link
Member

bf4 commented Aug 26, 2015

ref: #1058

@joaomdmoura
Copy link
Member Author

It does not seems to receive a lot of back up so I'm closing it as well in favor of #1058

@joaomdmoura joaomdmoura closed this Sep 3, 2015
@joaomdmoura joaomdmoura deleted the enabling-fields-option-to-json-adapter branch September 3, 2015 04:47
@vasilakisfil
Copy link
Contributor

I can't believe it that this was never merged :) The API for fields was excellent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to filter attributes?
3 participants