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.
On Feb 26, 8:19 am, Vasanthakumar Csk <rails-mailing-l...@andreas-
s.net> wrote:> 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.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---