question: class ControllerAthing def a_method end end class ControllerBthing def b_method ControllerAthing::a_method #this is what i want to do end end but when i do that i can an error: undefined method `a_method'' for ControllerAthing:Class thanks .. -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld wrote:> class ControllerAthing > def a_method > end > end > > class ControllerBthing > def b_method > ControllerAthing::a_method #this is what i want to do > end > end > > but when i do that i can an error: > undefined method `a_method'' for ControllerAthing:ClassBecause you''re treating #a_method as a class method when it is an instance method. Put #a_method into app/controllers/application.rb instead. This file defines the class ApplicationController which your other controllers inherit from, so this will make the method available in all controllers. -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Mark is right and the other option you have is use mixin ie create a module, put your a_method in it and include that module in both controller classes. This will make your a_method available in both controllers or in any controller in which you include that module. Cheers On Mar 10, 8:00 am, Shai Rosenfeld <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> question: > > class ControllerAthing > def a_method > end > end > > class ControllerBthing > def b_method > ControllerAthing::a_method #this is what i want to do > end > end > > but when i do that i can an error: > undefined method `a_method'' for ControllerAthing:Class > > 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 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 -~----------~----~----~----~------~----~------~--~---