Peter Michaux
2006-May-02 00:58 UTC
[Rails] Sharing function between helper and controller
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
Alain Ravet
2006-May-02 19:03 UTC
[Rails] Re: Sharing function between helper and controller
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