I would like to expose a global function to all aspects of my Ruby on Rails project (models, views, and controllers). Initially, I thought that I could just add:
def self.my_function
# Code here...
end
to /config/application.rb and then just call:
Application::my_function
anywhere in my application. But that didn't work. So I did some googling and it appears that I can expose global functions:
But not for all of them at once.
Can anybody tell me if what I want is possible?
I'd also like to avoid any include statements as much as possible as this is ideally supposed to be accessible from anywhere. But at this point, even using include statements would be OK if I can define the logic for this function in one central location.
define it in config/environment.rb
, before the app gets initialized with:
<YourApp>::Application.initialize!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With