3

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

前もって感謝します

4

3 に答える 3

4

これを試して ..

@videos=Video.where(:category => 'film',:grant => 'yes' ).order('created_at DESC').page(params[:page]).per_page(10)
于 2013-07-18T16:16:20.597 に答える
0

これをチェックして:

Video.where("category = ? AND `grant` = ?", "film", 1).order('created_at DESC').page(params[:page]).per_page(10)
于 2013-07-18T09:07:30.110 に答える