Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm getting a postgreSQL error on heroku that I don't get locally on my computer which also uses postgreSQL.

I have a search form with checkboxes and a model with boolean fields. When I check the box to find all reports that are completed, the form passes the parameter value completed='on'. As shown by the heroku logs, the database doesn't like using that parameter value with a boolean in its sql. I would have thought rails would somehow change it from 'on' to true, regardless, the search form works fine locally.

How can I get this to work on Heroku?

Once the website is live on Heroku how do I test future changes if there are issues like this where it works locally but not on the server? Does Heroku give you an area for testing a different version of your app?

Details:

Local Development Log

[1m[35mReport Load (0.8ms)[0m  SELECT "reports".* FROM "reports" WHERE ("reports"."user_id" = 1) AND (completed = 'on') LIMIT 4 OFFSET 0

Heroku Log

ActiveRecord::StatementInvalid (PGError: ERROR:  invalid input syntax for type boolean: "on"
2011-06-08T00:17:21+00:00 app[web.1]: : SELECT  "reports".* FROM "reports" WHERE  ("reports"."user_id" = 2) AND (completed = 'on') LIMIT 4 OFFSET 0):
2011-06-08T00:17:21+00:00 app[web.1]:   app/controllers/reports_controller.rb:6:in `index'

Controller

def index
  @reports = Report.accessible_by(current_ability).search(params)
  @reports = @reports.paginate :per_page => 4, :page => params[:page]
  respond_to do |format|
    format.html
    format.xml  { render :xml => @reports }
  end
end

View

<%= form_tag(reports_path, :method => "get") do %>
<ul>    
    <li>
        <%= link_to 'Show All', reports_path %>
    </li>       
    <li>
    <%= label_tag(:report_number, "Report Number") %>
    <%= text_field_tag(:report_number,nil, :value => params[:report_number]) %>
    </li>
    <li>
    <%= label_tag(:job_number, "Job Number") %>
    <%= text_field_tag(:job_number,nil, :value => params[:job_number]) %>
    </li>
    <li>
    <%= label_tag(:has_failures, "Failures") %>
    <%= check_box_tag(:has_failures,nil, params[:has_failures]) %>
    </li>
    <li>
    <%= label_tag(:completed, "Completed") %>
    <%= check_box_tag(:completed, nil, params[:completed]) %>
    </li>

    <li>
        <%= submit_tag("Search") %>
    </li>                   
</ul>

<% end %>

Model

def self.search(criteria)
 if !criteria[:report_number].blank?
    where("report_number = ?",criteria[:report_number])
  elsif !criteria[:job_number].blank?
    joins(:site).
    where("sites.job_number = ?",criteria[:job_number])
  else
    composed_scope = scoped
    if !criteria[:has_failures].blank?
     composed_scope = composed_scope.where("has_failures = ?",criteria[:has_failures])
   end
   if !criteria[:completed].blank?
      composed_scope = composed_scope.where("completed = ?",criteria[:completed])
   end
   composed_scope
  end
end
share|improve this question

2 Answers

up vote 1 down vote accepted

This is probably due to a Postgres version mismatch. 'on' became a valid value for boolean fields in Postgres 8.4, so I guess Heroku is still on 8.3. You'll just need to make sure you pass true or false into your query instead.

As far as testing goes, you can indeed setup a staging environment. You can either setup two git remotes for production/staging per this article: http://devcenter.heroku.com/articles/multiple-environments.

Or you can setup a separate staging application and use heroku_san to work with your two applications.

share|improve this answer
1  
The shared databases are on version 8.3, the dedicated databases are on version 9. – mu is too short Jun 8 '11 at 2:22
Ah, good to know. – Alex Korban Jun 8 '11 at 2:29
Thanks for the answers. I'm running postgreSQL v9.0.3 on my computer. If I'm going to be developing a mix of different rails apps that run on either heroku shared database or dedicated databases do you have any recommendations for how to setup my system? ie. can I run postgreSQL v8.3 and v9 on the same computer or is there a better way to develop and deploy on the same db? I have a mac/os x snow leopard. – Daniel Jun 8 '11 at 3:33
I guess you'd have to install two versions of Postgres to get the environment as similar as possible. I haven't tried to do it myself but I think it should be possible. I just try to avoid DB specific queries and use ActiveRecord to build queries as much as possible. – Alex Korban Jun 8 '11 at 4:14

You will need to define the check box's unchecked and checked values, something like this:

check_box(object_name, method, options = {}, checked_value = "1", unchecked_value = "0")
share|improve this answer
You missed the "my computer which also uses postgreSQL" part of the question. – mu is too short Jun 8 '11 at 2:19
Oops I did it again :( – David Jun 8 '11 at 2:26
No worries, I had my "develop on the same database that you deploy on" macro ready as soon as I saw "Heroku" and "PostgreSQL" :) – mu is too short Jun 8 '11 at 2:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.