Hi Everyone, Can anyone pls tell me how to access a Common Function in "application.rb" controller in a Model. For example, i am having a function to find the Factorial of a number. Where should i place this function, so that i can access through out the application (in all controllers and models)? For now i have placed in "application.rb" controller.
If you need it in both controllers AND models then you probably want to wrap it in a plain Ruby class and include it in your models.
For example...
class MathLib def self.factorial(n) ... end end
Then you can call MathLib.factorial n anywhere in your code.
If this is code that you'd like to carry from project to project you might also consider making this a module, rather than a class, so that you can include the module in the classes that need to make use of the functionality.