How do I make an action available to multiple controllers an

I have an action in a controller that I need to make available to
other controllers and views.

I put the action in ApplicationController and ApplicationHelper but it
didn’t work.

Thank you for any help.

Jose Hales-Garcia wrote:

I have an action in a controller that I need to make available to
other controllers and views.

I put the action in ApplicationController and ApplicationHelper but it
didn’t work.

Thank you for any help.

ApplicationHelper houses methods for your views and not actions. If you
want actions to be shared by multiple controllers there are 2 ways of
doing this

Put your common action in ApplicationController

Write CommonController which will become a base class for all your

domain specific controllers .so it will look something like this

class CommonController < ApplicationController

def common_action

end

end

class Domain1Controller < CommonController

end

class Domain2Controller < CommonController

end

Now whenever you call common_action in either domains they will be
available for execution so url will like this

http://…/domain1/common_action
http://…/domain2/common_action

Hope this helps

-Rajesh

At 11:41 AM 2/7/2007, you wrote:

I have an action in a controller that I need to make available to
other controllers and views.

I put the action in ApplicationController and ApplicationHelper but it
didn’t work.

Try putting the shared code into a module and mixing it in. It worked
for me.

-Kathy Van Stone
[email protected]