hi everyone, i got a simple question that''s bothering me all day: is it possible to find out which method and controller did the original call? to make this a little clearer, I want to do the following: (let''s say these two methods are in different controllers) def first_method say_my_name end def say_my_name # how do i get the original method and controller # invoking_method = ? # invoking_controller =? puts invoking_method puts invoking_controller end any help is appreciated! --~--~---------~--~----~------------~-------~--~----~ 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 14 Nov 2008, at 10:57, MaD wrote:> > hi everyone, > > i got a simple question that''s bothering me all day: > is it possible to find out which method and controller did the > original call? >You can screw around with caller but that''s not a very clean way to go about things. Fred> to make this a little clearer, I want to do the following: > (let''s say these two methods are in different controllers) > > def first_method > say_my_name > end > > def say_my_name > # how do i get the original method and controller > # invoking_method = ? > # invoking_controller =? > puts invoking_method > puts invoking_controller > end > > any help is appreciated! > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thanks! i just needed it for some log-entries anyway. so there is no need to find a cleaner way. On 14 Nov., 12:08, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 14 Nov 2008, at 10:57, MaD wrote: > > > > > hi everyone, > > > i got a simple question that''s bothering me all day: > > is it possible to find out which method and controller did the > > original call? > > You can screw around with caller but that''s not a very clean way to go > about things. > > Fred > > > to make this a little clearer, I want to do the following: > > (let''s say these two methods are in different controllers) > > > def first_method > > say_my_name > > end > > > def say_my_name > > # how do i get the original method and controller > > # invoking_method = ? > > # invoking_controller =? > > puts invoking_method > > puts invoking_controller > > end > > > any help is appreciated!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
As the OP was speaking of controllers: yes, you can. Check controller_name and action_name. But then:>> to make this a little clearer, I want to do the following: >> (let''s say these two methods are in different controllers)I see no way to have one controller calling instance methods on another controller. You could achieve this with components, but as the Rails docs state: you shouldn''t. /eno ===================================================================A wee piece of ruby every monday: http://1rad.wordpress.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yes you are right. my example was wrong. actually the second method ain''t in an controller, but in an initializer. and what i really wanted to do is log the calling controller_name and method_name. but i wanted to achieve this without having to add more parameters to my method call. of course i could just say: say_my_name(self.controller_name, self.method_name) but i''m lazy and i don''t want to type "(self.controller_name, self.method_name)" all the time, so i thought tried to find a way to figure out these infos inside the say_my_name-method. if there ain''t anything better than to parse caller, i''m gonna go with that. On 14 Nov., 12:30, "Enrico Thierbach" <enrico.thierb...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> As the OP was speaking of controllers: yes, you can. Check > controller_name and action_name. > > But then: > > >> to make this a little clearer, I want to do the following: > >> (let''s say these two methods are in different controllers) > > I see no way to have one controller calling instance methods on > another controller. You could achieve this with components, but as the > Rails docs state: you shouldn''t. > > /eno > > ===================================================================> A wee piece of ruby every monday:http://1rad.wordpress.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
actually, never mind. in my initializer self.controller_name self.action_name still return the names of my calling controller and action. guess that was just too easy to do in the first place. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---