Forum: Ruby on Rails writing a method that is accessible from any views as well as any controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C7935335b15e9c363b8decb26eb6fcfa?d=identicon&s=25 Mr. Bless (Guest)
on 2008-11-29 12:41
(Received via mailing list)
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.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2008-11-29 15:45
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à.
C7935335b15e9c363b8decb26eb6fcfa?d=identicon&s=25 Mr. Bless (Guest)
on 2008-12-01 07:15
(Received via mailing list)
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 Perez <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.