之前都这么写模糊查询,好像也没问题
hour = Hour.where("desc like ?", "#{today}").take
但是今天服务器上报错
ActionView::Template::Error (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc like '4') LIMIT 1' at line 1:
SELECT `hours`.* FROM `hours` WHERE (desc like '4') LIMIT 1):
我直接试了下 sql 查询,发现对于 mysql 必须写成
ELECT `hours`.* FROM `hours` WHERE (`desc` like '4') LIMIT 1):
那么是不是 rails 查询的时候也要写成
hour = Hour.where(" `desc` like ?", "#{today}").take
我看官方的资料上也没有这么写,什么时候应该要加``呢?求解惑