Reputation: 2004
I upgraded my app from Rails 3.2 to Rails 4.1, but now it's unable to display individual Answers. When I go to the show page for an answer (like '/answers/0183759926'), I get an error:
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "--- {} "
LINE 1: ... "answers" WHERE "answers"."id" IN (1862, '--- {}
^
SELECT "answers".* FROM "answers" WHERE "answers"."id" IN (1862, '--- {} ') ORDER BY answers.updated_at DESC
I have a model called Answers:
class Answer < ActiveRecord::Base
#...
default_scope { order('answers.updated_at DESC') }
obfuscate_id
#...
This is the controller:
def show
@answer = Answer.find(params[:id]) #relies on gem
end
I'm using the gem 'obfuscate_id' to scramble the displayed ID:
gem 'obfuscate_id', :git => 'https://github.com/namick/obfuscate_id.git'
How do I fix the error?
Update:
This seems to be an issue with the gem's find method. See https://github.com/namick/obfuscate_id/issues/19
Upvotes: 0
Views: 462
Reputation: 2004
This issue is caused by a incompatibility between the current gem and Rails 4.1. To circumvent it, I called Answer.deobfuscate_id
to get the actual id
, and then used find_by(id: )
on the actual id
.
Upvotes: 1