Sharing function between helper and controller


#1

Hi,

I have a utility function repeated in both my helper and my
controller. Not DRY. I have this repetition because other functions
in the helper and in the controller both use the utility function.
Where do I put this function so that both the helper and controller
can access the function? Mayber there is a different solution?

Thanks,
Peter


#2

Peter

> Where do I put this function so that both the helper and 

controller
> can access the function? Mayber there is a different solution?

helper_method() is what you need.

In the controller: (ex: application.rb)

 helper_method :tx_, :dev?
 def dev?
     ENV['RAILS_ENV']=='development'
 end

=> you can also use it in views.

Alain