Calling action from one controller to second

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 …

Shai R. 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:Class

Because 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.

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 R. [email protected]