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.
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
Hassan S. ------------------------ [email protected]
twitter: @hassan
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs