How can i use @model.map(&:attributes) to make it so that virtual attributes show up in when I render @model as json
Asked
Active
Viewed 515 times
0
-
Your example doesn't tell us what `@model` is. As a singular name I'd assume it's an ActiveRecord object but then calling `#map` on it makes no sense. – noodl Aug 02 '12 at 16:25
-
.map(&:attributes) is shorthand for mapping all attributes of @model without having to manually specify them. – p01nd3xt3r Aug 02 '12 at 16:38
1 Answers
1
@model.to_json(:method => ['virtual_attribute1', 'virtual_attribute2']))
Didn't understand the map
call either

Anthony Alberto
- 10,325
- 3
- 34
- 38
-
.map(&attributes) is short hand for mappng all the attribute of an object and your answer worked perfectly. Thx man. – p01nd3xt3r Aug 02 '12 at 16:36