You could put the formatting function in your Application controller,
then use the helper_method to give the view access. The code below
will allow you to use ‘my_formatting_method’ in a view.
class ApplicationController < ActionController::Base
self.send :helper_method, :my_formatting_method
On Jul 16, 11:47ï¿½am, “[email protected]”
Depending on how many methods (or the nature of them) you want to share,
you can also put them in a module and include the module in a helper.
config/environment.rb (at the bottom)
requiring the module in environment.rb makes it available all over the
application, so you don’t have to require it in every file you might
want to use it in. It immediately becomes available to all of your
controllers. Mixing the module into the helper makes all of the modules
methods available in the helper, and since you generally have the
“helper :all” statement in application.rb, the helper will get picked up
automatically and it will be available to all of your views.
I was struggling to share some methods a few weeks ago, and came upon
this by trial and error.