In my Rails 3 application I have a module containing my own helpers which overrides a couple of the built in rails helpers:
module MyHelpers
def form_for(*args)
...
end
def link_to(*args)
...
end
end
The above module lives in the lib folder.
I would like these helpers to only be used on specific controller actions. My first stab at this was something like this :
require "my_helpers"
class MyController < ApplicationController
before_filter :add_helpers
def add_helpers
if some_condition
ApplicationHelper.send(:include, MyHelpers)
end
end
..
end
Module.send(:include, ModuleB) is a valid way to include a module within another module, but it doesn't do what I need in this situation : the methods in my module are not available in the view. It seems as though Rails has already determined which helper methods will available to the view before any of the controller methods are run.
Is there a way to do what I need?
I know I could globally override the form_for method but I'd rather not do this.
I think the answer to this would come from understanding how rails makes helper methods accessible to the view.
form_for
andlink_to
are doing. – Benjamin Udink ten Cate Apr 5 '13 at 9:56link_to
is not working as Rails says it should. As Benjamin suggests, I'd recommend renaming the methods, and updating your views where necessary. – osahyoun Apr 5 '13 at 10:26