Mysql2 ::错误:您的SQL语法中有错误

时间:2012-02-23 01:49:15

标签: mysql ruby-on-rails ruby-on-rails-3 mysql-error-1064 mysql2

我刚刚使用this将我的rails app db从sqlite3切换到mysql2,这似乎可以正常运行。

但是当我启动我的应用程序时,我现在得到了这个:

A ActionView::Template::Error occurred in pages#dashboard:

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 '== 1) LIMIT 20 OFFSET 0' at line 1: SELECT `tickets`.* FROM `tickets` WHERE (archived == 1) LIMIT 20 OFFSET 0
activerecord (3.0.3) lib/active_record/connection_adapters/abstract_adapter.rb:202:in `log'

不确定在哪里可以正常使用。任何帮助,将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:4)

试试这个:

# Notice single = vs ==
WHERE (archived = 1)

<强>更新 结束了

scope :is_archived, where('archived != ?', 1)
scope :not_archived, where('archived = ?', 1)

这很有效。谢谢!