Forum: Ruby on Rails application_helper.rb vs application.rb

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.
Aa575b7606897a056f073f0f148804dd?d=identicon&s=25 Gareth Reeves (reevesg)
on 2006-03-16 19:00
I find that I want to put the same methods into both of these files.
Whats the best way to get away with a single implemenation?

Gareth
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-03-17 11:20
(Received via mailing list)
Am Donnerstag, den 16.03.2006, 19:00 +0100 schrieb Gareth Reeves:
> I find that I want to put the same methods into both of these files.
> Whats the best way to get away with a single implemenation?

You can make controller methods available in view as helper methods
using the following macro:

# controller
def my_method
  # do something here
end

helper_method :my_method

The other way is, to include a module with your method in both files.

--
Norman Timmler

http://blog.inlet-media.de
This topic is locked and can not be replied to.