Здравствуйте, работает авторизация и регистрация на сайте. Реализована с помощью гемов Devise i Omniauth.
Но при авторизации с помощью соц. сетей не все нужные данные сохраняться в БД.
В таблицу добавил поля: name, picture, birthday, link.
В модели сделаны соответствующие записи:
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
В результате данные записываться только в поле - name. А вот в поля picture, birthday, link идет nil.
Update
Схема:
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
Миграция:
class AddPictureFieldForUser < ActiveRecord::Migration
def change
add_column :users, :picture, :string
add_column :users, :birthday, :string
add_column :users, :link, :string
end
end
Логи:
(0.1ms) begin transaction
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'maxprofkom@gmail.com' LIMIT 1
SQL (0.3ms) INSERT INTO "users" ("provider", "uid", "name", "email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["provider", "facebook"], ["uid", "1714712178749597"], ["name", "Maxim Cherevatov"], ["email", "maxprofkom@gmail.com"], ["encrypted_password", "$2a$10$gI0hCiXiMaECDjVP9UNAjeqw8XuVq/fytswpMajPbrH8xkut7y8UK"], ["created_at", "2016-03-11 10:24:39.273235"], ["updated_at", "2016-03-11 10:24:39.273235"]]
(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" = ? [["last_sign_in_at", "2016-03-11 10:24:39.298250"], ["current_sign_in_at", "2016-03-11 10:24:39.298250"], ["last_sign_in_ip", "127.0.0.1"], ["current_sign_in_ip", "127.0.0.1"], ["sign_in_count", 1], ["updated_at", "2016-03-11 10:24:39.299035"], ["id", 1]]
(22.9ms) commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 153ms (ActiveRecord: 46.3ms)