# Writing a method that is accessible from any views as well as any controller

**URL:** <https://www.ruby-forum.com/t/writing-a-method-that-is-accessible-from-any-views-as-well-as-any-controller/154429>\
**Category:** Rails\
**Created:** [November 29, 2008, 12:41pm UTC](https://www.ruby-forum.com/t/writing-a-method-that-is-accessible-from-any-views-as-well-as-any-controller/154429 "2008-11-29T12:41:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrSBless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@MrSBless](https://www.ruby-forum.com/u/MrSBless)\
**Post date:** [November 29, 2008, 12:41pm UTC](https://www.ruby-forum.com/t/writing-a-method-that-is-accessible-from-any-views-as-well-as-any-controller/154429/1 "2008-11-29T12:41:47Z")

</div>

HI guys where should i have to write the method that it is accessible  
from any controller and any views. When i write the method in  
application controller then it is accessible in controller only and  
when i write it on application helper it is accessible on views only.  
I even tried to write it as module in the lib and included in the  
application controller, in that case it becomes inaccessible in views.

---

<div class="post-metadata">

**Author:** ![MrSBless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@MrSBless](https://www.ruby-forum.com/u/MrSBless)\
**Post date:** [November 29, 2008, 3:45pm UTC](https://www.ruby-forum.com/t/writing-a-method-that-is-accessible-from-any-views-as-well-as-any-controller/154429/2 "2008-11-29T15:45:13Z")

</div>

Mr. Bless wrote:

> HI guys where should i have to write the method that it is accessible  
> from any controller and any views. When i write the method in  
> application controller then it is accessible in controller only and  
> when i write it on application helper it is accessible on views only.  
> I even tried to write it as module in the lib and included in the  
> application controller, in that case it becomes inaccessible in views.

Write the code in ApplicationController, declare it as protected. Then  
to make it accessible to views, still in application.rb, use the method:  
helper\_method(your\_method\_name), and voilÃ .

---

<div class="post-metadata">

**Author:** ![MrSBless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@MrSBless](https://www.ruby-forum.com/u/MrSBless)\
**Post date:** [December 1, 2008, 7:15am UTC](https://www.ruby-forum.com/t/writing-a-method-that-is-accessible-from-any-views-as-well-as-any-controller/154429/3 "2008-12-01T07:15:50Z")

</div>

Thanks Perez. What i do now is that i write it in application helper  
and include it in application controller.

On Nov 29, 9:45 am, Fernando P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
