Search code examples
ruby-on-railsherokuruby-on-rails-3.2heroku-postgres

PG::Error: ERROR: argument of WHERE must be type boolean, not type integer


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


Solution

  • Your where clause isn't calling anything to compare with, so PG doesn't know what to include in the results. A where clause must evaluate to true/false.

    You are probably looking for something like:

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

    That way you're comparing your where clause to see if its included in the cities result from the first line... though I'm not sure that will work either, since your first line is returning a set of SubjectGradeCity objects instead of city objects. But you can maybe figure it out from there?

    Edit: You should also take NickM's advice on moving these kind of methods out of the view. They should definitely be at the model layer.