Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 4 Rails查询工作,然后创建一个错误_Ruby On Rails 4_Rails Activerecord - Fatal编程技术网

Ruby on rails 4 Rails查询工作,然后创建一个错误

Ruby on rails 4 Rails查询工作,然后创建一个错误,ruby-on-rails-4,rails-activerecord,Ruby On Rails 4,Rails Activerecord,我有一个查询来检索给定日期的所有可用时间 @takenspots = Spot.joins(:reservations).where('reservations.date = ?', params[:date]) if @takenspots.any? @availablespots = Spot.where('id != ?', @takenspots.map) 我使用@availablespots填充一个选择列表 我每天有4个不同的点,查询只运行2次。2

我有一个查询来检索给定日期的所有可用时间

@takenspots = Spot.joins(:reservations).where('reservations.date = ?', params[:date])
        if @takenspots.any?
          @availablespots = Spot.where('id != ?', @takenspots.map)
我使用@availablespots填充一个选择列表

我每天有4个不同的点,查询只运行2次。2/4点

如果你试着预订一天,我从4个景点中选了2个,它会说:

SQLite3::SQLException: near ",": syntax error: SELECT "spots".* FROM "spots"  WHERE (id != 1,2)
但我不明白为什么它在前两个位置有效而在剩下的两个位置无效。。。 有人有主意吗


谢谢你,

我不知道为什么这会起作用,但它确实起作用,所以这可能会对某人有所帮助:

@availablespots = Spot.where('id not in (?)',@takenspots.map(&:id))

OP的问题是我不明白为什么它在前两个位置有效而在剩下的两个位置无效。。。有人有主意了。所以,你的回答应该解释为什么事情没有按预期的那样进行。我不知道为什么它实际上有效,但现在它确实有效了。所以我没有把它作为答案,但它可能会帮助一些人。