Ruby on rails 3 在密码表中设计字段
使用密码表中的每个字段轻松设置Desive gem是否可能,该表映射了属于用户模型的密码模型(只有一个Ruby on rails 3 在密码表中设计字段,ruby-on-rails-3,devise,Ruby On Rails 3,Devise,使用密码表中的每个字段轻松设置Desive gem是否可能,该表映射了属于用户模型的密码模型(只有一个电子邮件字段) 换句话说,这是我想要的模型设计图: +-------+ | User | +-------+ | email | +-------+ ^ (have one) | | (belongs to) +--------
电子邮件
字段)
换句话说,这是我想要的模型设计图:
+-------+
| User |
+-------+
| email |
+-------+
^ (have one)
|
| (belongs to)
+------------------------+
| Password |
+------------------------+
| encrypted_password |
| reset_password_token |
| reset_password_sent_at |
| sign_in_count |
| ... |
+------------------------+
Deviate wiki非常完整,但没有关于这方面的任何信息。是的,有一种解决方法,包括覆盖Deviate内部方法(这是不推荐的) 然而,我没有很好地测试它(我只创建了一个用户并尝试登录),这可能会在Desive中引入一些bug和不可预测的行为。因此,请确保在将此代码交付生产之前对应用程序进行了良好的测试 数据库可验证模块的解决方案包括:
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
t.string :email
t.timestamps
end
create_table :passwords, :force => true do |t|
t.integer :user_id
t.string :encrypted_password, :null => false, :default => ""
end
end
end
我使用以下方法创建了一个用户:
x = User.new
x.password_record = Password.new
x.password = "123456"
x.email = "a@b.com"
x.save
我在操作中测试了符号,\u,它成功了
您可以使用带有的注册表单创建。要检查如何对其他模块执行相同的操作,请查看Desive源代码(),看看它使用了哪些属性以及如何工作()。非常感谢,@rodrigo flores。谢谢你的精心设计。
x = User.new
x.password_record = Password.new
x.password = "123456"
x.email = "a@b.com"
x.save