Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 593073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:48:24+00:00 2026-05-13T15:48:24+00:00

I am trying to use the Whenever plugin for rails to perform a model

  • 0

I am trying to use the Whenever plugin for rails to perform a model process at certain times.

When I try to use the mail_out process in my User model, I get the following error. Can someone please point me in the right direction of what is going wrong?

/var/lib/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:48: /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:380:in `load_without_new_constant_marking': /home/tnederlof/Dropbox/Ruby/daily_trailer/app/models/user.rb:9: syntax error, unexpected tIDENTIFIER, expecting ')' (SyntaxError) @users = find(:all, :conditions => "#{weekday}sub = "t"")

My schedule.rb is as follows:

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

My User model is:

class User < ActiveRecord::Base

  acts_as_authentic

  def self.mail_out

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

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


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


  end

end

My User_mailer is:

class UserMailer < ActionMailer::Base
    def mail_out(users)
    @recipients = { }
    users.each do |user|
      @recipients[user.email] = { :name => user.name }
    end


    from        "no-reply@dailytrailer.net"
    subject     "Check out the trailer of the day!"
    body        :user => user
  end

end

Migration:

  create_table "users", :force => true do |t|
    t.string   "email"
    t.date     "birthday"
    t.string   "gender"
    t.string   "zipcode"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "crypted_password"
    t.string   "password_salt"
    t.string   "persistence_token"
    t.string   "mondaysub",         :default => "f", :null => false
    t.string   "tuesdaysub",        :default => "f", :null => false
    t.string   "wednesdaysub",      :default => "f", :null => false
    t.string   "thursdaysub",       :default => "f", :null => false
    t.string   "fridaysub",         :default => "f", :null => false
    t.string   "saturdaysub",       :default => "f", :null => false
    t.string   "sundaysub",         :default => "f", :null => false
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:48:24+00:00Added an answer on May 13, 2026 at 3:48 pm

    Change this line

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

    to

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

    The conditions key for find method takes either an array or hash as the value. If you are using array then the first element of the array straightaway converted into a “where” clause sql statement if you dont have any question marks in it and if you have then those question marks are substituted with the further elements of the array. For instance, changing the above to question mark notation will become

    @users = find(:all, :conditions => ["#{weekday}sub = ?", 't'])
    

    when ‘t’ is a string

    Its better to use question mark notation because it is more secure as you don’t do string interpolation within your sql string which can be very harmful for you app data.

    You can also write your query to hash conditions like so

    @users = find(:all, :conditions => {"#{weekday}sub".to_sym => 't'})
    

    Most people prefer this over array notation in other words consider this as the rails way of doing it.

    And another point, looking at your UserMailer#mailout method, you don’t need to do

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

    in your User.mailout method, you can just do

    UserMailer.deliver_mail_out(@users)
    

    because you are already extracting each user object from the users array in your UserMailer#mailout and adding them to the recipients.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the Optiflag package in my Ruby code and whenever I
I trying to use ImageInfo and Jython to get information from a image on
I am trying to use the whenever gem to execute a couple of rake
I'm trying to use a dictionary. Whenever I want to check if an element
I'm trying to use Microsoft.Office.Interop.Excel. It seems to load fine but when I try
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use a guid as a resource id in a rest url but
While trying to use LINQ to SQL I encountered several problems. I have table
I' trying to use a Linq query to find and set the selected value
I'm trying to use svnmerge.py to merge some files. Under the hood it uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.