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

Including :settings in to_json #71

Open
mkanthan opened this issue Apr 19, 2016 · 2 comments
Open

Including :settings in to_json #71

mkanthan opened this issue Apr 19, 2016 · 2 comments

Comments

@mkanthan
Copy link

Hi,

I'm wondering if there is a way to include the settings.all hash when you're converting a user object to JSON, such as:

user.to_json(:include => :settings)
user.to_json(:include => { :settings => :all })

These methods do not seem to work, as the JSON hash will just contain "settings": null. Is there any way to accomplish this? I am on version 1.2.0 which I understand is old.

@luizkowalski
Copy link

I have the same need
I would like to include the settings in the response built by serializer
My serializer looks like this

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

adding :settings doesn't work and it is really needed for me
Do you know any workaround?

@luizkowalski
Copy link

Updated: I added to_settings_hash in my serializer, but the JSON response is ugly

"to_settings_hash": {
    "language": {
      "prefered": [
        "de",
        "en"
      ]
    }
  }

I would prefer something like preferences instead to_settings_hash

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

No branches or pull requests

2 participants