Usage of methods in application.rb


#1

Hi all,
I’m having some methods in application.rb. I have to use those
methods in my model.
How can i do that?
Thanks in advance.


#2

I think can do like

ins = ApplicationController.new
ins.method_name #method_name is any def in pplication
controller

    But why are you  calling controller methods from model

Sijo


#3

I’d agree with Sijo here - if you need controller models in the model,
something has gone wrong with your design. Either the methods are
really model methods (maybe class methods on the model?), or you’re
trying to do view stuff in the models. Can you post an example of
where you’re running into this problem?

–Matt J.

On Mar 18, 5:52 am, Priya B. removed_email_address@domain.invalid


#4

Sijo Kg wrote:

I think can do like

ins = ApplicationController.new
ins.method_name #method_name is any def in pplication
controller

    But why are you  calling controller methods from model

Sijo

I need those methods in many places, so i wrote in application.rb. I’m
calling those methods in another method which is in application.rb.


#5

So move such code to lib folder and include those modules where ever you
need using include statement

Sijo


#6

Sijo Kg wrote:

So move such code to lib folder and include those modules where ever you
need using include statement

Sijo

Ya i created a file and moved those methods to lib folder and checked.
Its working fine.


#7

Sijo Kg wrote:

So move such code to lib folder and include those modules where ever you
need using include statement

Sijo

Thank you very much for your good suggestion…