0
我正在使用設計模型進行註冊,其中包含其他字段。ActiveRecord不提取某些字段
這是我的用戶表模式
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "provider", default: "email", null: false
t.string "uid", 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.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "username", null: false
t.string "email", null: false
t.integer "role", default: 0, null: false
t.datetime "premium_expires_at"
t.string "token", default: "", null: false
t.text "tokens", limit: 65535
t.datetime "created_at"
t.datetime "updated_at"
t.string "avatar"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true, using: :btree
t.index ["username"], name: "index_users_on_username", unique: true, using: :btree
end
然而,通過ActiveRecord的(用戶模式)查詢表的時候,我不能獲取屬於制定某些列。
例如
userList = User.select("id, confirmation_token, confirmed_at, username, uid, role")
測井USERLIST給我
#<ActiveRecord::Relation [#<User id: 1, uid: "[email protected]", username: "bowie", role: "admin", avatar: nil>, #<User id: 2, uid: "[email protected]", username: "wilson", role: "user", avatar: nil>, #<User id: 3, uid: "[email protected]", username: "Cartman", role: "user", avatar: nil>]>
的confirmation_token字段和被檢索confirmed_at令牌字段未啓用。還有什麼我應該做的?
當你放入userList.confirmation_token或放入userList.confirmed_at時,它會打印什麼? – 31piy
嗯..我實際上能夠檢索值時,我循環通過數組作爲user.confirmation_token ..但它似乎仍然不是數組的一部分。更像是一種檢索值 – Kannaj