# Method in Model

**URL:** <https://www.ruby-forum.com/t/method-in-model/63168>\
**Category:** Rails\
**Created:** [June 12, 2006, 10:40pm UTC](https://www.ruby-forum.com/t/method-in-model/63168 "2006-06-12T22:40:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [June 12, 2006, 10:40pm UTC](https://www.ruby-forum.com/t/method-in-model/63168/1 "2006-06-12T22:40:14Z")

</div>

I have a simple method in a model, to send out e-mails via the  
script/runner.

def Reminder.dropoff  
@messages = Reminder.find(:all, :conditions =\> [“time \< now()”])  
@messages.each do |mes|  
Mailman::deliver\_send\_message(mes)  
end  
end

However, it’s not sending e-mails.

When this exact code was dropped in a controller, it worked great… is  
there something different about methods in models that I would need to  
apply here?

Thanks!  
-stirman

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [June 12, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/method-in-model/63168/2 "2006-06-12T23:42:24Z")

</div>

Or perhaps an alternate question…

Can you call methods in a Controller from a Model?

Thanks,  
-stirman

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [June 12, 2006, 11:51pm UTC](https://www.ruby-forum.com/t/method-in-model/63168/3 "2006-06-12T23:51:06Z")

</div>

Jason S. wrote:

> Or perhaps an alternate question…
> 
> Can you call methods in a Controller from a Model?
> 
> Thanks,  
> -stirman

The way I have accomplished this in the past is by making the method an  
action on a controller, then activating it with “wget  
[http://localhost/controller/action](http://localhost/controller/action)”. You can just run that command from  
a cron job and be good to go.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [June 13, 2006, 12:12am UTC](https://www.ruby-forum.com/t/method-in-model/63168/4 "2006-06-13T00:12:39Z")

</div>

Jason S. wrote:

> Indeed, worked perfect.
> 
> Are there any performance hits using wget vs. script/runner? Any  
> obvious reason to use one over the other?
> 
> Thanks again!  
> -stirman

I can’t imagine there being a performance hit for accessing the action  
via wget. Think about it: all it does is hit your existing web server  
with a request. You don’t even have to return anything if you don’t want  
to. I don’t know how script/runner does its magic, but it can’t be much  
different.

Overall, I just feel more comfortable having the system respond to  
events the same way in every case, instead of building a custom  
interface for some scheduled task.

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [June 13, 2006, 12:03am UTC](https://www.ruby-forum.com/t/method-in-model/63168/5 "2006-06-13T00:03:26Z")

</div>

Indeed, worked perfect.

Are there any performance hits using wget vs. script/runner? Any  
obvious reason to use one over the other?

Thanks again!  
-stirman

Bryan D. wrote:

> The way I have accomplished this in the past is by making the method an  
> action on a controller, then activating it with “wget  
> [http://localhost/controller/action](http://localhost/controller/action)”. You can just run that command from  
> a cron job and be good to go.
> 
> Hope this helps.

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [June 15, 2006, 1:22pm UTC](https://www.ruby-forum.com/t/method-in-model/63168/6 "2006-06-15T13:22:08Z")

</div>

#if bryan.duxbury /\* Jun 12, 11:51 \*/

> [http://localhost/controller/action](http://localhost/controller/action)". You can just run that command from  
> a cron job and be good to go.
> 
> Hope this helps.  
> #endif /\* removed\_email\_address@domain.invalid \*/

One thing i would add to that is, consider the security implications of  
doing it this way. someone in $internet\_land could invoke that method  
at will. Unless of course, you protect access to it.

–  
keys: [http://codex.net/gpg.asc](http://codex.net/gpg.asc)

The trouble with the world is that the stupid are cocksure  
and the intelligent are full of doubt.  
– Bertrand Russell
