用导轨设计 5 [英] Devise with rails 5

查看:33
本文介绍了用导轨设计 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用设计在 rails 5 中制作一个应用程序.但是在迁移设计使用的用户模型后,结果如下:

I am making an app in rails 5 with devise. But after migration of user model which is used by devise the results are following:

User.new =>
    User id: nil,
    email: "",
    created_at: nil,
    updated_at: nil. 

while 它应该显示为:

while It should be shown like:

User id: nil,
email: "",
encrypted_password: "",
reset_password_token: nil,
reset_password_sent_at: nil,
remember_created_at: nil,
sign_in_count: 0,
current_sign_in_at: nil,
last_sign_in_at: nil,
current_sign_in_ip: nil,
last_sign_in_ip: nil,
created_at: nil,
updated_at: nil,
name: nil

这意味着没有创建字段.但是当我看到 mysql 数据库时,所有字段都在用户表中创建.那么为什么它没有显示在 rails 控制台内?

It means fields are not being create. but when I see the mysql database all the fields are being created inside users table. Then why it is not showing inside rails console?

以下是schema.rb:

Following are the schema.rb:

ActiveRecord::Schema.define(version: 20160717050914) do

  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.string   "confirmation_token"
    t.datetime "confirmed_at"
    t.datetime "confirmation_sent_at"
    t.string   "unconfirmed_email"
    t.integer  "failed_attempts",        default: 0,  null: false
    t.string   "unlock_token"
    t.datetime "locked_at"
    t.datetime "created_at",                          null: false
    t.datetime "updated_at",                          null: false
    t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
    t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
  end

end

推荐答案

这是因为 devise 覆盖了检查方法,不显示它们的内部属性.看到这个:https://github.com/plataformatec/devise/blob/29142418bade74224d98bbf5bbcadfba181d5db9/lib/devise/models/authenticatable.rb#L119-L124

This is because devise overrides the inspect method, to not show their internal attributes. See this: https://github.com/plataformatec/devise/blob/29142418bade74224d98bbf5bbcadfba181d5db9/lib/devise/models/authenticatable.rb#L119-L124

无论如何,他们在那里.只是没有在 inspect 方法中打印出来.

Anyway, they're there. Just not printed out in the inspect method.

要查看您可以使用的所有属性:

To see all the attributes you can use:

user = User.first
user.attributes # => returns a hash containing all the attributes 

或者例如获取current_sign_in_ip:

user.current_sign_in_ip # => #<IPAddr: IPv4:xxx.xxx.xxx.xxx/255.255.255.0>

这篇关于用导轨设计 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆