Leszek Andrukanis
Leszek Andrukanis

Reputation: 2125

Can I use other helpers methods in application_helper.rb?

I have a question about the availability of methods defined in app/helpers.

Can I share methods in helpers, (for example, use methods defined in my_helper.rb in application_helper.rb), or are they restricted to views ?

Upvotes: 3

Views: 1108

Answers (1)

sunkencity
sunkencity

Reputation: 3472

You should be able to do that if you have this in controller or application_controller:

helper :all

But it seems a little too complex to have helpers that call out to other helpers, generally helper methods should be short simple and have little dependencies, they should do one simple thing for the view, each. Makes it harder to test I suppose if you have helper methods that call out to other helpers.

If the problem you are trying to solve with this is sufficiently complex I'd suggest trying to move it to a module in the lib directory and then include that module in the helpers that need the common functionality.

Upvotes: 3

Related Questions