I don't believe you can pass params using the methods option. One
approach would be to calculate the outcome on the collection before
calling to_json.
def calculate_outcome(arg)
@outcome = # do calculation with arg
end
def outcome
@outcome
end
collection.each {|c| c.calculate_outcome(arg)}
collection.to_json(:methods => [:income, :outcome])
HTH,
Nicholas
On Jun 23, 4:45 am, Gregory Peck <[email protected]>
wrote:
> Hello,
>
> Is there possible to pass arguments for serialized methods using
> to_json??
> I want to serialize my collection of users with income and outcome which
> is calculate by methods:
>
> collection.to_json(:methods => [:income, :outcome])
>
> But, what if I need to pass some arguments to method :outcome ?
>
> Thanks
> --
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---