Question

I would to nest some helper methods to simplify my application_helper, for example I have a bunch of methods dealing with currencies which apply for the entire app and I would like to put in the currencies_helper and then simply include that entire helper into the application helper.

How can I do this?

I tried:

helper :currencies

and got

undefined method `helper' for ApplicationHelper:Module
Was it helpful?

Solution

Helpers in rails are just modules which get included in controllers to help share functionality between them. There's been some weirdness around helpers in rails 3, so depending on what version you're running things may or may not work as you expect out the box.

Essentially what you want to do is add helper :all to your application_controller which will include ALL helpers in ALL your controllers. If this isn't what you want you can specify the specific helpers you want helper :currencies for example.

In the rails 3 betas helper :all was the default behavior, but I think they've reverted that in the latest release.

There's a great article that discusses how this works in rails 2, but there may be differences in rails 3, but it should be a good starting point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top