Forum: Ruby on Rails Method in Model

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.
261243fcd1aebe2d71684fe9d4d80d87?d=identicon&s=25 Jason S. (stirman)
on 2006-06-12 22:40
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
261243fcd1aebe2d71684fe9d4d80d87?d=identicon&s=25 Jason S. (stirman)
on 2006-06-12 23:42
Or perhaps an alternate question...

Can you call methods in a Controller from a Model?

Thanks,
-stirman
2c84fb7ef6efff1269442d6bbb8c43d8?d=identicon&s=25 Bryan D. (bryanduxbury)
on 2006-06-12 23:51
Jason Stirman 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". You can just run that command from
a cron job and be good to go.

Hope this helps.
261243fcd1aebe2d71684fe9d4d80d87?d=identicon&s=25 Jason S. (stirman)
on 2006-06-13 00:03
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 Duxbury 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". You can just run that command from
> a cron job and be good to go.
>
> Hope this helps.
2c84fb7ef6efff1269442d6bbb8c43d8?d=identicon&s=25 Bryan D. (bryanduxbury)
on 2006-06-13 00:12
Jason Stirman 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.
Vincent AE Scott (Guest)
on 2006-06-15 13:22
(Received via mailing list)
#if bryan.duxbury /* Jun 12, 11:51 */
> http://localhost/controller/action". You can just run that command from
> a cron job and be good to go.
>
> Hope this helps.
#endif /* bryan.duxbury@gmail.com */

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

 The trouble with the world is that the stupid are cocksure
 and the intelligent are full of doubt.
 -- Bertrand Russell
This topic is locked and can not be replied to.