# No helper methods in controller

**URL:** <https://www.ruby-forum.com/t/no-helper-methods-in-controller/48063>\
**Category:** Rails\
**Created:** [November 16, 2005, 2:03pm UTC](https://www.ruby-forum.com/t/no-helper-methods-in-controller/48063 "2005-11-16T14:03:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [November 16, 2005, 2:03pm UTC](https://www.ruby-forum.com/t/no-helper-methods-in-controller/48063/1 "2005-11-16T14:03:20Z")

</div>

Hi

I’m on rails version 0.14.3.  
The methods of the controller helper module are not available in the  
controller instance. They are available on the view. Verified it with a  
plain new project.

May this be a bug or am I missing something?

thanks a lot in advance

Martin

---

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [November 16, 2005, 2:42pm UTC](https://www.ruby-forum.com/t/no-helper-methods-in-controller/48063/2 "2005-11-16T14:42:50Z")

</div>

On 16.11.2005, at 15.03, Martin wrote:

> Hi
> 
> I’m on rails version 0.14.3.  
> The methods of the controller helper module are not available in the  
> controller instance. They are available on the view. Verified it  
> with a  
> plain new project.
> 
> May this be a bug or am I missing something?

No, that’s like it’s supposed to be. Helpers are methods meant to  
make views cleaner by encapsulating common behaviour in one place.  
They are thus not available in controllers.

You can, however, include them in your controllers, as well:

include DateHelper

You might consider, however, whether your code is in the right place  
in helpers if you need a lot of it often in controllers in contrast  
to views.

//jarkko

---

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [November 16, 2005, 2:45pm UTC](https://www.ruby-forum.com/t/no-helper-methods-in-controller/48063/3 "2005-11-16T14:45:52Z")

</div>

On Wed, Nov 16, 2005 at 02:03:20PM +0100, Martin wrote:

> I’m on rails version 0.14.3.  
> The methods of the controller helper module are not available in the  
> controller instance. They are available on the view. Verified it with a  
> plain new project.
> 
> May this be a bug or am I missing something?

I can confirm it here as well. Don’t know what’s going on, though.

Ronny

---

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [November 16, 2005, 2:55pm UTC](https://www.ruby-forum.com/t/no-helper-methods-in-controller/48063/4 "2005-11-16T14:55:00Z")

</div>

jarkko wrote:

> > May this be a bug or am I missing something?  
> > No, that’s like it’s supposed to be. Helpers are methods meant to  
> > make views cleaner by encapsulating common behaviour in one place.  
> > They are thus not available in controllers.
> 
> You can, however, include them in your controllers, as well:
> 
> include DateHelper  
> That makes sense, and by using “include” it works (standard ruby stuff).  
> But if this is true there are some serious “errors” in the Rails book.

## From page 554:

## By default, each controller gets its own helper module. It wonâ??t be surpris- ing to learn that Rails makes certain assumptions to help link the helpers into the controller and its views. If a controller is named BlogController, it will automatically look for a helper module called BlogHelper in the file blog\_helper.rb in the app/helpers directory.

## and there is even an example with

class ParticularController \< ApplicationController  
helper :date\_format

# …

* * *

and rails is not complaining when I am using “helper” but it does not  
work.

?

Martin

---

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [November 16, 2005, 3:00pm UTC](https://www.ruby-forum.com/t/no-helper-methods-in-controller/48063/5 "2005-11-16T15:00:57Z")

</div>

On Wed, Nov 16, 2005 at 03:42:26PM +0200, Jarkko L. wrote:

> No, that’s like it’s supposed to be. Helpers are methods meant to  
> make views cleaner by encapsulating common behaviour in one place.  
> They are thus not available in controllers.
> 
> You can, however, include them in your controllers, as well:
> 
> include DateHelper

Hmm, the API docs at  
[http://api.rubyonrails.com/classes/ActionController/Helpers/ClassMethods.html](http://api.rubyonrails.com/classes/ActionController/Helpers/ClassMethods.html)  
probably needs to be updated. (Or does it reflect 1.0?)

‘helper :something’ doesn’t work, ‘include SomeHelper’ works.

Ronny

---

<div class="post-metadata">

**Author:** ![martin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/73ab20/32.png) [@martin](https://www.ruby-forum.com/u/martin)\
**Post date:** [November 16, 2005, 4:08pm UTC](https://www.ruby-forum.com/t/no-helper-methods-in-controller/48063/6 "2005-11-16T16:08:26Z")

</div>

Ronny and Martin,

On 16.11.2005, at 15.55, Guest wrote:

> into the controller and its views. If a controller is named
> 
> # …
> 
> * * *
> 
> and rails is not complaining when I am using “helper” but it does not  
> work.

Using “helper :myhelper” will make the helper available in _the  
views_ of that particular controller.

So helper is a perfectly working method but it’s not meant to do what  
you think it is.

Also, like Torben mentioned, the api docs at least seem to be fine.  
The fact that the helpers are not available in the controller code  
could perhaps be stated clearly, tho. Do I hear someone volunteering  
for a documentation patch?

//jarkko
