Rails counter 在 mysql 里面的问题

brucebot · 2012年12月06日 · 最后由 brucebot 回复于 2012年12月07日 · 2100 次阅读

大家好,我又来提问了

我在 controller 里面使用了

@active_users = User.order(':topics_count,:comments_count').limit(12)

在本地用 sqlite3 测试没有问题,但是跑到 mysql 上就出现了这个问题

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 ':topics_count,:comments_count LIMIT 12' at line 1: SELECT  `users`.* FROM `users`  ORDER BY :topics_count,:comments_count LIMIT 12):

这是为什么呢?怎么来处理

有这样写的么,你看看你出来的 sql 就不对啊

#1 楼 @fresh_fish mysql 怎么用不懂啊,我以为 sqllite3 可以的话,就可以了。 这个要怎么写呢?

@active_users = User.order('topics_count, comments_count').limit(12)

@zgm @Rei 谢谢两位,看来本地测试还是也用 mysql 比较好,保持和服务器一致

需要 登录 后方可回复, 如果你还没有账号请 注册新账号