views:

167

answers:

2

There is an ApplicationHelper in an engine we're using that looks like this:

module ApplicationHelper
  def page_title()
    # ...
  end
end

This gets called by a number of views in the engine. I'd like to override this method in my application to provide a different default title. How do I do this? Simply defining my own ApplicationHelper didn't seem to work.

+2  A: 

Did you define the page_title method in your ApplicationHelper module? Just having an ApplicationHelper by itself won't do it.

By default, your ApplicationHelper module should already be in app/helpers/application_helper.rb. Your app files are required by rails after it requires the plugins you are using. That means any method you define in app/helpers/application_helper.rb should override methods defined in the plugins code.

This behavior arises out of ruby's open class structure. Any time, anywhere any class/module/object can be reopened to add methods and attributes to it. More or less.

Could you post some of the code you are trying to override the engine method with?

BaroqueBobcat
+1  A: 

Are other methods defined in your ApplicationHelper available?

If yes, the engine helper is probably loaded before your ApplicationHelper, and your method overwritten.

If no, Rails may never have loaded your module because it thinks it already knows about ApplicationHelper and doesn't try to load it again.

Tor Erik Linnerud