# QUICK QUESTION: Method in Controller AND Helper

**URL:** <https://discuss.rubyonrails.org/t/quick-question-method-in-controller-and-helper/15674>\
**Category:** rubyonrails-talk\
**Created:** [July 15, 2007, 3:32am UTC](https://discuss.rubyonrails.org/t/quick-question-method-in-controller-and-helper/15674 "2007-07-15T03:32:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleksander\_Valtyshev](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@Aleksander\_Valtyshev](https://discuss.rubyonrails.org/u/Aleksander_Valtyshev)\
**Post date:** [July 15, 2007, 3:32am UTC](https://discuss.rubyonrails.org/t/quick-question-method-in-controller-and-helper/15674/1 "2007-07-15T03:32:44Z")

</div>

Is it possible to have method(s) in application\_helper.rb available for controllers, just like for views? Actually my method is current\_user too 😃 and looks pretty similar, but I'd like it in application\_helper.rb...

---

<div class="post-metadata">

**Author:** ![Florian\_Assmann](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@Florian\_Assmann](https://discuss.rubyonrails.org/u/Florian_Assmann)\
**Post date:** [July 15, 2007, 9:57am UTC](https://discuss.rubyonrails.org/t/quick-question-method-in-controller-and-helper/15674/2 "2007-07-15T09:57:14Z")

</div>

James Schementi schrieb:

> ahoge wrote:
> 
> > Is it possible to have method(s) in application\_helper.rb available for controllers, just like for views? Actually my method is current\_user too 😃 and looks pretty similar, but I'd like it in application\_helper.rb...
> 
> define the method in your helper, then include your helper at the top of the controller:
> 
> class ApplicationHelper &nbsp;&nbsp;def method\_to\_use\_in\_controller &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;end end
> 
> class ApplicationController &nbsp;&nbsp;include ApplicationHelper end
> 
> that's the easiest way to do it ... but if you have a lot of methods in your ApplicationHelper you may want to pull it out into a module that gets included into both the helper and controller.

Hi James,

instead of mixin in a whole helper module I'd declare the Helper method as module\_function like:

module SomeHelper &nbsp;&nbsp;1000.times do |index| &nbsp;&nbsp;&nbsp;&nbsp;define\_method(:"waste\_#{index}") { index \*\* 2 } &nbsp;&nbsp;end &nbsp;&nbsp;def some\_method(\*some\_args) &nbsp;&nbsp;&nbsp;&nbsp;some\_args.inspect &nbsp;&nbsp;end

&nbsp;&nbsp;module\_function :some\_method end

In your controller you can then do:

class Somes \< ApplicationController &nbsp;&nbsp;def some\_action &nbsp;&nbsp;&nbsp;&nbsp;SomeHelper.some\_method &nbsp;&nbsp;end end

Don't pollute your controller... 😉

Regards Florian

---

<div class="post-metadata">

**Author:** ![Aleksander\_Valtyshev](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@Aleksander\_Valtyshev](https://discuss.rubyonrails.org/u/Aleksander_Valtyshev)\
**Post date:** [July 16, 2007, 1:40am UTC](https://discuss.rubyonrails.org/t/quick-question-method-in-controller-and-helper/15674/3 "2007-07-16T01:40:51Z")

</div>

Thanks
