ruby on rails - Only load helpers on specific controller actions -


in rails 3 application have module containing own helpers overrides couple of built in rails helpers:

module myhelpers   def form_for(*args)      ...   end    def link_to(*args)      ...   end end 

the above module lives in lib folder.

i these helpers used on specific controller actions. first stab @ :

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) valid way include module within module, doesn't need in situation : methods in module not available in view. seems though rails has determined helper methods available view before of controller methods run.

is there way need?

i know globally override form_for method i'd rather not this.

i think answer come understanding how rails makes helper methods accessible view.

since rails automatically loads , includes helpers in app/helpers directory, try putting helpers in different location, instance in lib directory.

this way .rb-files parsed , loaded module wouldn't included in applicationhelper class automatically. in before filter stated.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -