M
M
Max2016-03-10 22:03:30
Ruby on Rails
Max, 2016-03-10 22:03:30

Why is not all data written to the database when visiting the site using omniauth ( Facebook, VK )?

Hello, the authorization and registration on the site is working. Implemented with Devise and Omniauth gems.
But when logging in with the help of social. networks, not all the necessary data is stored in the database.
Added fields to the table: name, picture, birthday, link.
The corresponding entries are made in the model:

def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.name = auth.info.name
user.picture = auth.info.picture
user.birthday = auth.info.birthday
user.link = auth.info.link
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
end
end

As a result, the data is written only in the field - name. But in the fields picture, birthday, link goes nil.
Update
Scheme:
create_table "users", force: :cascade do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at",                          null: false
    t.datetime "updated_at",                          null: false
    t.string   "provider"
    t.string   "uid"
    t.string   "name"
    t.string   "picture_file_name"
    t.string   "picture_content_type"
    t.integer  "picture_file_size"
    t.datetime "picture_updated_at"
    t.string   "picture"
    t.string   "birthday"
    t.string   "link"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

Migration:
class AddPictureFieldForUser < ActiveRecord::Migration
  def change
  	add_column :users, :picture, :string
  	add_column :users, :birthday, :string
  	add_column :users, :link, :string
  end
end

Logs:
(0.1ms)  begin transaction
  User Exists (0.1ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
  SQL (0.3ms)  INSERT INTO "users" ("provider", "uid", "name", "email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)  
   (22.3ms)  commit transaction
   (0.1ms)  begin transaction
  SQL (0.2ms)  UPDATE "users" SET "last_sign_in_at" = ?, "current_sign_in_at" = ?, "last_sign_in_ip" = ?, "current_sign_in_ip" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ?  
   (22.9ms)  commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 153ms (ActiveRecord: 46.3ms)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question