Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 查询以检查RubyonRails中的整数值_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 查询以检查RubyonRails中的整数值

Ruby on rails 查询以检查RubyonRails中的整数值,ruby-on-rails,ruby,Ruby On Rails,Ruby,我想在rails应用程序中执行此查询 Video.where("category= 'film' AND grant = 1").order('created_at DESC').page(params[:page]).per_page(10) 这里grant存储一个整数值 我得到了以下错误 Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your

我想在rails应用程序中执行此查询

   Video.where("category= 'film' AND grant = 1").order('created_at DESC').page(params[:page]).per_page(10)
这里grant存储一个整数值

我得到了以下错误

    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
提前感谢

检查此项:

Video.where("category = ? AND `grant` = ?", "film", 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)

问题在于格兰特。GRANT是MySql中的保留字。你应该在它们周围用回记号

Video.where("category= 'film' AND `grant` = 1").order('created_at DESC').page(params[:page]).per_page(10)

我想我能胜任这项工作。请参阅

谢谢,它对我有用。。。但我不知道为什么其他查询不起作用。我还将:grant=>'yes'更改为:grant=>'1'。因为我的“grant”存储的是整数值。一个更像Rails的实现将使用
where(category:“film”,grant:1)
。如果我们想使用或而不是AND呢?