查询以检查rails上的ruby中的整数值
我想在rails app中执行此查询
Video.where("category= 'film' AND grant = 1").order('created_at DESC').page(params[:page]).per_page(10)
这里授予存储整数值。
我收到了以下错误
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 'grant = 1) ORDER BY created_at DESC LIMIT 10 OFFSET 0' at line 1: SELECT `videos`.* FROM `videos` WHERE (category= 'film' AND grant = 1) ORDER BY created_at DESC LIMIT 10 OFFSET 0
提前致谢
问题在于补助金。 GRANT是MySql中的保留字。 你应该在它们周围使用反向标记。
Video.where("category= 'film' AND `grant` = 1").order('created_at DESC').page(params[:page]).per_page(10)
我会做的工作。 请参阅保留字
试试这个 ..
@videos=Video.where(:category => 'film',:grant => 'yes' ).order('created_at DESC').page(params[:page]).per_page(10)
检查一下:
Video.where("category = ? AND `grant` = ?", "film", 1).order('created_at DESC').page(params[:page]).per_page(10)