rails 3,find_by_sql,date_format,参数太少错误

时间:2011-11-23 03:58:19

标签: ruby-on-rails ruby-on-rails-3

我有以下find_by_sql并且收到“参数太少”错误。有什么想法要修复吗?想把它保存为find_by_sql

dates=find_by_sql(['select DATE(start_datetime) date_only,  DATE_FORMAT(start_datetime,\'\%b \%D\') as formatted_date from events where area_id=1 group by date_only'])

THX

1 个答案:

答案 0 :(得分:1)

您需要使用双百分比符号来转义取景器内的百分比:

dates = find_by_sql(['select DATE(start_datetime) date_only,  DATE_FORMAT(start_datetime,\'\%%b \%%D\') as formatted_date from events where area_id=1 group by date_only'])