Pls i have the following code in my model
Letter.count(:id, :conditions => ["language_id = #{lang} AND :created_at => '#{start_date.to_date.strftime('%Y-%m-%d')}'..'#{end_date.to_date.strftime('%Y-%m-%d')}' " ])
I am trying to get the count of letters.id of different letters between the given dates.
This is the error an having…
Please those anyone know what am doing wrong…Thanks
SQLite3::SQLException: near ">": syntax error: SELECT COUNT("letters"."id") FROM "letters" WHERE ("letters".language_id = 1) AND (language_id = 1 AND :created_at => '2011-05-01'..'2011-05-08
This can be much simplified. A couple points:
:created_at => ...format within a stringbetween ? and ?for dates.strftimeyour dates, Rails will handle this automatically.where(...)instead of a:conditionsHash for yourcount(...).language_idfield tooLetter.where("language_id = ? AND created_at between ? and ?", lang, start_date.to_date, end_date.to_date).count