Hi.
The file
/rails/activesupport/lib/active_support/json/encoders/enumerable.rb
Has:
class Array
(...)
def as_json(options = nil) #:nodoc:
self
end
end
I want a as_json method FooModel.all.as_json(:only => [...]) that will
work same as FooModel.first.as_json(:only => [...]).
I had to write my own method in a initializer:
class Array
def as_json_preserve_only_keys(preserve_keys)
self.collect do |el|
el.as_json(:only => preserve_keys)
end
end
end
Is there a better way to do this? Why does the Array method now look at
the "options" parameter?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.