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.
Gareth R. (Guest)
on 2006-03-16 20: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
Norman T. (Guest)
on 2006-03-17 12:20
(Received via mailing list)
Am Donnerstag, den 16.03.2006, 19:00 +0100 schrieb Gareth R.:
> 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 T.

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