Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Rails Helpers w/ Same Method Name

I have two different helper files (photos_helper & comments_helper) w/ that have a method named actions_for. How can I explicitly call which helper method that I need? I know that I could just rename one of them but I would prefer to keep them the same. I tried PhotosHelper::actions_for but that doesn't seem to work.

like image 849
Kyle Decot Avatar asked Jun 09 '11 06:06

Kyle Decot


1 Answers

In Rails 3 all helpers are always (in Rails 3.1 a patch exists to selectively allow helpers again) included. What's happening behind the scenes:

class YourView
  include ApplicationHelper
  include UserHelper
  include ProjectHelper

  ...
end

So depending on the order Rails includes them, any of your actions_for methods will be used. There is no way you can explicitly chose one of them.

If you would have to explicitly call ProjectHelper.action_for, you could also name your methods project_action_for - simplest solution.

like image 142
Marcel Jackwerth Avatar answered Oct 02 '22 01:10

Marcel Jackwerth