Forum: Ruby on Rails Usage of methods in application.rb

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-18 10:52
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.
661ae6e97d0e16c2af2aaf7d197e8387?d=identicon&s=25 Sijo k g (sijo)
on 2009-03-18 13:49
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
6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2009-03-18 18:50
(Received via mailing list)
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 Jones

On Mar 18, 5:52 am, Priya Buvan <rails-mailing-l...@andreas-s.net>
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-19 09:16
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.
661ae6e97d0e16c2af2aaf7d197e8387?d=identicon&s=25 Sijo k g (sijo)
on 2009-03-19 10:19
So move such code to lib folder and include those modules where ever you
need using include statement

Sijo
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-19 11:13
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.
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-19 11:13
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..
This topic is locked and can not be replied to.