rails for mysql2 gem for .include?

时间:2011-07-25 01:48:04

标签: mysql ruby-on-rails-3

这适用于本地,但不适用于生产服务器。

使用ubuntu 10.04,rails 3.0.7,ruby 1.9.2和mysql2 gem

我做错了什么?

haml view:

- unless current_user.surveys.include?(survey)

返回

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 'NULL))) LIMIT 1' at line 1: SELECT  1 FROM `surveys` INNER JOIN `response_sets` ON `surveys`.id = `response_sets`.survey_id WHERE `surveys`.`id` = 1 AND ((`response_sets`.user_id = 1) AND ((completed_at NOT NULL))) LIMIT 1):

修改

使用名为surveyor的宝石。在不编辑实际gem的情况下,我必须在用户模型中创建关联:

has_many :response_sets
has_many :surveys, :through => :response_sets, :conditions => ["completed_at NOT NULL"]
has_many :responses, :through => :response_sets

数据库表:

1 个答案:

答案 0 :(得分:2)

我很确定语法是“IS NOT NULL”,而不仅仅是“NOT NULL”。我在MySQL实例上运行了一个测试,当我遗漏了IS

时出错了