0

I am getting this heroku error,

these are my Heroku logs.

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| %>

this is my code in the views


<% 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? %>

help please..

4

2 回答 2

4

您的 where 子句没有调用任何可比较的内容,因此 PG 不知道要在结果中包含什么。子句必须where评估为真/假。

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

<% 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 对象而不是 city对象。但你也许可以从那里弄清楚?

编辑:您还应该接受 NickM 的建议,将这些方法移出视图。他们绝对应该在模型层。

于 2013-10-15T20:19:28.403 回答
2

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

于 2013-10-15T20:29:55.017 回答