# Can I call a function from app/controller/application.rb into app/models?

**URL:** <https://www.ruby-forum.com/t/can-i-call-a-function-from-app-controller-application-rb-into-app-models/125520>\
**Category:** Rails\
**Created:** [January 9, 2008, 10:12pm UTC](https://www.ruby-forum.com/t/can-i-call-a-function-from-app-controller-application-rb-into-app-models/125520 "2008-01-09T22:12:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [January 9, 2008, 10:12pm UTC](https://www.ruby-forum.com/t/can-i-call-a-function-from-app-controller-application-rb-into-app-models/125520/1 "2008-01-09T22:12:57Z")

</div>

Can I call a function from app/controller/application.rb in app/  
models?  
because when I run test units, I got “NoMethodError: undefined method  
`get\_person’ for #Class:0x6aec8f0”  
but I define get\_person into application.rb. and I know, when run  
rails, the first time load controller, then models, at last is view.  
So I think, I can call this method “get\_person” from application.rb in  
models, but there is wrong. why?  
Thanks!

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [January 9, 2008, 10:15pm UTC](https://www.ruby-forum.com/t/can-i-call-a-function-from-app-controller-application-rb-into-app-models/125520/2 "2008-01-09T22:15:54Z")

</div>

OnRails wrote:

> Can I call a function from app/controller/application.rb in app/  
> models?  
> because when I run test units, I got “NoMethodError: undefined method  
> `get\_person’ for #Class:0x6aec8f0”  
> but I define get\_person into application.rb. and I know, when run  
> rails, the first time load controller, then models, at last is view.  
> So I think, I can call this method “get\_person” from application.rb in  
> models, but there is wrong. why?  
> Thanks!

You can’t call the method without being or having an instance of a  
controller that extends ApplicationController. I suggest learning more  
about object-oriented programming.
