views:

23

answers:

1

I am trying to use the Whenever plugin for rails to perform a model process at certain times. My schedule.rb is as follows:

 every 1.day, :at => '5:30 am' do
    runner "User.mail_out"
  end

My model is as follows:

class User < ActiveRecord::Base

  acts_as_authentic

  def mail_out

    weekday = Date.today.strftime('%A').downcase

    @users = find(:conditions => "#{weekday}sub = t")

    @users.each { |u| UserMailer.deliver_mail_out(u)}   


  end

end

When I try to run the script/runner -e development "User.mail_out" command, I get the following error:

/var/lib/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:48: undefined method `mail_out' for #<Class:0xb708bd50> (NoMethodError)
    from (eval):1
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `eval'
    from /var/lib/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:48
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from script/runner:3

Can anyone point out what is going wrong? Also how can I manually invoke the mail_out process (from command line) to test the functionality of my mailing system.

Thank you!

+1  A: 

You're getting that error because you've defined the mail_out method as an instance method instead of a class method. To fix it, change the method definition line to (add self.):

def self.mail_out

To test it from the command line, do something like this:

script/runner "User.mail_out"

You might want to puts or print something so you get some feedback on what happened.

Alex Reisner
Thank you for the help. Now I get a new error, I updated my post above. Also I included my mail script. Any ideas of what is not working?
Trevor Nederlof
Good question, but please try to refrain from changing your question significantly after an answer is posted. The goal of this site is to build a collection of web pages with useful responses to specific questions, not just for the question askers, but for the whole development community, including anyone reading this page in the future. Your new question is not related to the original (not totally your fault--it may seem related), so it would be clearer to post it as a new question. (Also, this is the second useful answer I've given you--see your previous questions--how about a vote?)
Alex Reisner
Sorry, I am still getting the hang of this site. I will post a new question. And I marked your answers :) Thanks for the help.
Trevor Nederlof
Trevor, no worries--thanks for the votes! I would have answered your new question but I was out for a couple of hours. See you around on the site, and good luck with your projects.
Alex Reisner