I love that I can use .send() to dynamically build the name of the method I want to call, but how do I build a variable length list of parameters to go along with it? I am trying to write a helper for dealing with routing and nested resources. Rails sets me up with methods the look like this; edit_resource_path (resource) edit_resource_nested_path(resource, nested) edit_resource_nested_double_nested_path(resource, nested, double_nested) ...and so on as deep as I have nested my resources. I can easily construct the name of the method I have to call like this; method_name = ("edit_#{object.class.to_s.underscore}_path") ..but to call it with .send() I need to supply various sets of parameters. I was hoping I could just stuff them in an array and send the array, but this didn''t work. any other ideas? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 10, 6:43 am, Garrett Berneche <punkrockdontc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > ..but to call it with .send() I need to supply various sets of > parameters. I was hoping I could just stuff them in an array and send > the array, but this didn''t work. any other ideas?foo.send(:some_method, *array_of_parameters) Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 10, 1:43 pm, Garrett Berneche <punkrockdontc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I love that I can use .send() to dynamically build the name of the > method I want to call, but how do I build a variable length list of > parameters to go along with it? > > I am trying to write a helper for dealing with routing and nested > resources. Rails sets me up with methods the look like this; > > edit_resource_path (resource) > edit_resource_nested_path(resource, nested) > edit_resource_nested_double_nested_path(resource, nested, > double_nested) > > ...and so on as deep as I have nested my resources. > > I can easily construct the name of the method I have to call like > this; > method_name = ("edit_#{object.class.to_s.underscore}_path") > > ..but to call it with .send() I need to supply various sets of > parameters. I was hoping I could just stuff them in an array and send > the array, but this didn''t work. any other ideas?arg = [param1, param2, ...] Object.send(method, *arg) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---