简体   繁体   中英

Obfuscated Id Postgres Error in Rails 4

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM