On Jul 18, 6:08 am, Lost Warrior
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> hi please gice explanation for this
>
> 1: def json_attributes_for(model, *attrs)
> 2: attrs = [attrs].flatten.map(&:to_s)
> 3: model.attributes.delete_if{|k,v| !attrs.include?(k) }.to_json
> 4: end
It returns a json hash for the object, but only including the
specified attributes. It''s rewriting the wheel though, first of hashes
have a slice method so that messing around with delete_if is not
needed, and secondly to_json takes a :only option.
Fred> --
> Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---