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

api is ignoring "only" configuration #1807

Closed
luizkowalski opened this issue Jun 15, 2016 · 1 comment
Closed

api is ignoring "only" configuration #1807

luizkowalski opened this issue Jun 15, 2016 · 1 comment

Comments

@luizkowalski
Copy link
Contributor

I have a serializer like this

class UserSerializer < ActiveModel::Serializer
  attributes :access_token, :first_name, :last_name
end

in one specific controller, I don't want to return first name and last name, so I've done this

class V1::Auth::AnonymousController < ApplicationController
  def create
    render json: User.create(activation_state: 'anonymous'), only: :access_token, status: 201
  end
end

in previous version (0.9.5) it was working, but when I updated to 0.10.0, it returns the first_name and last_name as empty values on the JSON

I'm using Ruby 2.3.1p112 with Rails 4.2.6

@groyoh
Copy link
Member

groyoh commented Jun 15, 2016

You need to use the fields option instead of only e.g. render json: user, fields: [:access_token], status: 201. Seems like the docs are missing for this options, maybe you would be willing to create a PR for it?

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

No branches or pull requests

3 participants