Reputation: 37
I moved my app from sqlite to postgresql so that I could use RGeo and PostGIS. I deleted all the data in my database and started from scratch. Everything is working fine except one particular area of the site. I have an association that links Tourstops and Venues that appears to be not working. No code was modified in this area since the switch. Unfortunately I'm still sort of new to rails and don't know enough to diagnose this error.
The error I'm getting is:
ActiveRecord::StatementInvalid in ToursController#show
PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type integer LINE 1: SELECT "venues".* FROM "venues" WHERE (1) LIMIT 1 ^ : SELECT "venues".* FROM "venues" WHERE (1) LIMIT 1
def show
@tour = Tour.find(params[:id])
@tourstop = Venue.find_by(params[:id])
end
Parameters: {"id"=>"1"}
Upvotes: 2
Views: 638
Reputation: 76774
Your problem, as stated in the comments, that you're using find_by
without any :key in the hash
To be clear, ActiveRecord should be able to translate between SQLite & PGSQL, so the difference has to be with your use of the ActiveRecord methods:
find
Finds individual element by primary_key:
Model.find(id)
find_by
Finds by value other than primary_key:
Model.find_by name: "Rich"
Model.find_by({name: "Rich"})
Upvotes: 4