I login user using omniauth and then store some attributes in the database. Here is how I remove the blank attributes of the omniauth hash and select some attributes
def update_blank_attributes(attributes,force_update_attr)
attributes.each { |k,v| puts attributes.delete(k) unless (force_update_attr.include?(k)||read_attribute(k).blank?) }
update_attributes!(attributes)
end
My User model has a data class which is a json data type:
class AddDataToUsers < ActiveRecord::Migration
def change
add_column :users, :data, :json
end
end
This works fine locally , even after dropping and recreating database .
However I get following error on heroku:
ActiveRecord::StatementInvalid (PG::InvalidTextRepresentation: ERROR: invalid input syntax for type json
DETAIL: Token "=" is invalid.
CONTEXT: JSON data, line 1: "linkedin_data"=...
: INSERT INTO "users" ("created_at", "data", "email", "name", "provider", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"):
app/models/user.rb:68:in `update_blank_attributes'
app/controllers/authentications_controller.rb:38:in `create'
PG::InvalidTextRepresentation: ERROR: invalid input syntax for type json
CONTEXT: JSON data, line 1: "linkedin_data"=...
DETAIL: Token "=" is invalid.
local PG version:9.3.3
Heroku PG version: 9.3.3
I am getting/saving the same data from Linkedin in local as well as in heroku since its exact same call to linkedin for authentication
What database do you use locally? Is it a Postgres database and is it the same version as that used on Heroku? What version of Postgres are you using on Heroku? (you can find out with something like
heroku pg:info -a appname
...
PG Version: 9.2.6
So I guess my hypothesis is that you're using different versions, and so you're not seeing the problem locally. Either that, or you have different data in the Heroku app so you're seeing the problem manifest there.
重新启动heroku dynos为我解决了这个问题
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.