# Helper in controller undefined when called

**URL:** <https://www.ruby-forum.com/t/helper-in-controller-undefined-when-called/178247>\
**Category:** Rails\
**Created:** [October 31, 2009, 8:48pm UTC](https://www.ruby-forum.com/t/helper-in-controller-undefined-when-called/178247 "2009-10-31T20:48:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicpon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4491bb/32.png) [@nicpon](https://www.ruby-forum.com/u/nicpon)\
**Post date:** [October 31, 2009, 8:48pm UTC](https://www.ruby-forum.com/t/helper-in-controller-undefined-when-called/178247/1 "2009-10-31T20:48:45Z")

</div>

Hello, I’m pulling my hair out as I can’t seem to find resolution to my  
simple problem, which is calling methods from controllers to helpers.

in my application\_controller.rb I have helper :all, which as i  
understand should include all helpers all the time.  
Then when i try to call methods in helpers i get undefined method error.

Is there another place where i have to include helpers to make them  
available in controllers?

---

<div class="post-metadata">

**Author:** ![nicpon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4491bb/32.png) [@nicpon](https://www.ruby-forum.com/u/nicpon)\
**Post date:** [November 1, 2009, 3:50am UTC](https://www.ruby-forum.com/t/helper-in-controller-undefined-when-called/178247/2 "2009-11-01T03:50:51Z")

</div>

Helper methods are used in the template class (ActionView::Template),  
not controllers. If I’m reading the documentation right, putting  
“helper :all” in a controller makes all helpers found in app/helpers/  
\*\*/\*rb available in that controller’s views.

On Oct 31, 3:48 pm, Great J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![nicpon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4491bb/32.png) [@nicpon](https://www.ruby-forum.com/u/nicpon)\
**Post date:** [November 12, 2009, 11:03am UTC](https://www.ruby-forum.com/t/helper-in-controller-undefined-when-called/178247/3 "2009-11-12T11:03:26Z")

</div>

If you really want to use an existing Rails helper in your  
controllers, do the following :

1. add the following the following code to your  
application\_controller (a singleton and a method):  
class Helper  
include Singleton  
include ActionView::Helpers::DateHelper  
include ActionView::Helpers::TextHelper
# include other helpers

end

def helpers  
Helper.instance  
end

1. Use the helpers in your controller : @nice\_string =  
helpers.distance\_of\_time\_in\_words(@t1,@t2)

Regards,  
MVCaraiman.

On Oct 31, 8:48 pm, Great J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
