# Calling controller function from model private method

**URL:** <https://www.ruby-forum.com/t/calling-controller-function-from-model-private-method/132735>\
**Category:** Rails\
**Created:** [March 24, 2008, 8:03am UTC](https://www.ruby-forum.com/t/calling-controller-function-from-model-private-method/132735 "2008-03-24T08:03:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [March 24, 2008, 8:03am UTC](https://www.ruby-forum.com/t/calling-controller-function-from-model-private-method/132735/1 "2008-03-24T08:03:39Z")

</div>

Hi,

I have private methods written in my user model. I have schedule crontab  
to execute these methods like:  
ruby -e production “User.private\_function”

But now i will have to either access global variable of the application  
with in the private method or be able to call controller function  
through crontab!

Any suggestions?

Regards,  
Sandeep G

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [March 24, 2008, 8:08am UTC](https://www.ruby-forum.com/t/calling-controller-function-from-model-private-method/132735/2 "2008-03-24T08:08:29Z")

</div>

I meant I was calling these prvate methods thru crontab :  
ruby script/runner -e production User.private\_function

Sandeep G. wrote:

> Hi,
> 
> I have private methods written in my user model. I have schedule crontab  
> to execute these methods like:  
> ruby -e production “User.private\_function”
> 
> But now i will have to either access global variable of the application  
> with in the private method or be able to call controller function  
> through crontab!
> 
> Any suggestions?
> 
> Regards,  
> Sandeep G

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [March 24, 2008, 9:43am UTC](https://www.ruby-forum.com/t/calling-controller-function-from-model-private-method/132735/3 "2008-03-24T09:43:50Z")

</div>

> Sandeep G. wrote:
> 
> > Hi,
> 
> > I have private methods written in my user model. I have schedule crontab  
> > to execute these methods like:  
> > ruby -e production “User.private\_function”
> 
> > But now i will have to either access global variable of the application  
> > with in the private method or be able to call controller function  
> > through crontab!

Sounds like you should rewrite your model so that it doesn’t depend on  
these things. A model should never be calling a controller and global  
variables are usually a bad idea.

Fred
