Rails is a universal global function

I would like to open a global function for all aspects of my Ruby on Rails project (models, views, and controllers). Initially, I thought I could just add:

def self.my_function
    # Code here...
end

in / config / application.rb and then just call:

Application::my_function

anywhere in my application. But that did not work. Thus, I did some search queries, and it looks like I can expose global functions:

  • For my controllers in / app / controllers / application _controller.rb
  • For my views in / app / helpers / application _helper.rb
  • For my models in / lib /

But not for everyone at once.

Can someone tell me if it is possible that I want?

, , , , . include- , .

+5
1

config/environment.rb, :

<YourApp>::Application.initialize!
+10

All Articles