PG ::错误:错误:WHERE的参数必须是boolean类型,而不是类型integer

时间:2013-10-15 20:07:03

标签: ruby-on-rails heroku ruby-on-rails-3.2 heroku-postgres

我收到了这个heroku错误,

这些是我的Heroku日志。

2013-10-15T19:51:45.703129+00:00 app[web.1]:  19: <% cities = SubjectGradeCity.includes(:city).collect(&:city).uniq %>
2013-10-15T19:51:45.703129+00:00 app[web.1]:  20: <% grades = SubjectGradeCity.includes(:grade).where(:city_id).collect {|s| {:name => s.grade.name, :id => s.grade.id}}.uniq %>
2013-10-15T19:51:45.703129+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR:  argument of WHERE must be type boolean, not type integer
2013-10-15T19:51:45.703129+00:00 app[web.1]: LINE 1: ...ade_cities".* FROM "subject_grade_cities"  WHERE ("subject_g...
2013-10-15T19:51:45.703129+00:00 app[web.1]:                                                              ^
2013-10-15T19:51:45.703129+00:00 app[web.1]: 17: <%= simple_form_for :assignments_filter , :html => {:id => "assignments_filter_form"}, :url => {:controller => "requests", :action => "assignments2"  } do |f| %>

这是我在视图中的代码


<% cities = SubjectGradeCity.includes(:city).collect(&:city).uniq %>
<% grades = SubjectGradeCity.includes(:grade).where(:city_id).collect {|s| {:name => s.grade.name, :id => s.grade.id}}.uniq %>
<% subjects = SubjectGradeCity.includes(:subject).where(:city_id).collect {|s| {:name => s.subject.name, :id => s.subject.id}}.uniq %>
<% grades.unshift({:name => "You have to select your city first", :id => ""}) if grades.empty? %>
<% subjects.unshift({:name => "You have to select your city first", :id => ""}) if subjects.empty? %>

请帮助..

2 个答案:

答案 0 :(得分:4)

您的where子句不会调用任何可比较的内容,因此PG不知道要在结果中包含什么。 where子句必须求值为true / false。

你可能正在寻找类似的东西:

<% cities = SubjectGradeCity.includes(:city).collect(&:city).uniq %>
<% grades = SubjectGradeCity.includes(:grade).where(:city_id => cities).collect {|s| {:name => s.grade.name, :id => s.grade.id}}.uniq %>
<% subjects = SubjectGradeCity.includes(:subject).where(:city_id => cities).collect {|s| {:name => s.subject.name, :id => s.subject.id}}.uniq %>

这样你就比较了你的where子句,看它是否包含在城市中的第一行...虽然我不确定它是否会起作用,因为你的第一行是返回一组SubjectGradeCity对象而不是城市对象。但你可以从那里弄明白吗?

编辑:您还应该采纳NickM的建议,将这些方法移出视图。他们肯定应该在模型层。

答案 1 :(得分:2)

你永远不应该在你的视图中放置数据库查询。我至少会将它们移到帮助器上,但理想情况下应该在模型中定义它们。也就是说,只要你把它放在你的模型中,Helios的答案就是好的。