JBuilder "Except"

Hi,

I’m trying to use JBuilder to generate a JSON to a specific class.
I wan’t to include all attributes, except one or two.

To do that I’m doing:

json.extract! object, :attr1, :attr2, :attr3, :attr4, :attr5, …

There’s an alternative?

Att.

On Fri, May 16, 2014 at 8:59 PM, Henrique V.
[email protected] wrote:

I’m trying to use JBuilder to generate a JSON to a specific class.
I wan’t to include all attributes, except one or two.

json.extract! object, :attr1, :attr2, :attr3, :attr4, :attr5, …

There’s an alternative?

How about creating an array of what you do want e.g.

wanted = object.attributes.keys.map(&:to_sym) - [:attrX, :attrY]
json.extract! object, *wanted

HTH,

Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs