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

Added presenter method attr_expose to AR #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adamburmister
Copy link

I added a method attr_expose to the AR model which allows for easy declaration of attributes to include in the JSON response.

Under the cover it stores a list of attribute names and automatically passes those into the options[:only] array when serializable_hash is called.

class Account < ActiveRecord::Base
  attr_expose :full_name, :email
end

@Sutto
Copy link
Owner

Sutto commented Dec 31, 2012

I like the idea - it's nice and simple yet suitable powerful! I'm not sure it's something that necessarily belongs in RocketPants itself at the moment. I'd be more inclined to add it as a rocket_pants-presenter gem (which I'm happy to link to) if that'd make sense to you?

@softwaregravy
Copy link

Just came across this

Did anyone put these into a gem that could we could hook in?

@Sutto
Copy link
Owner

Sutto commented Aug 12, 2013

@softwaregravy I'm not aware of a gem, but you can solve it pretty similarly (using different syntax, and admittedly a bit more weight) using ActiveModel Serializers integration.

@softwaregravy
Copy link

I did end up going with the Serializers, thanks

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

Successfully merging this pull request may close these issues.

3 participants