ruby on rails 3 - Having a problem with my Model query -
ruby on rails 3 - Having a problem with my Model query -
pls have next code in model
letter.count(:id, :conditions => ["language_id = #{lang} , :created_at => '#{start_date.to_date.strftime('%y-%m-%d')}'..'#{end_date.to_date.strftime('%y-%m-%d')}' " ])
i trying count of letters.id of different letters between given dates. error having...
please know doing wrong...thanks
sqlite3::sqlexception: near ">": syntax error: select count("letters"."id") "letters" ("letters".language_id = 1) , (language_id = 1 , :created_at => '2011-05-01'..'2011-05-08
this can much simplified. couple points:
you don't utilize:created_at => ...
format within string you need utilize between ? , ?
dates. you don't need manually strftime
dates, rails handle automatically. in rails 3, preferred way utilize where(...)
instead of :conditions
hash count(...)
. you should utilize rails' safe interpolation language_id
field too letter.where("language_id = ? , created_at between ? , ?", lang, start_date.to_date, end_date.to_date).count
ruby-on-rails-3
Comments
Post a Comment