1

我有一个名为 Person 的模型。我希望用户从人继承。

class Person < ActiveRecord::Base
  belongs_to :organization
  validates :email, :presence => true, :uniqueness => true
end

class User < Person

  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable, :lockable

  # for some reason I HAVE TO user attr_accessor on the following attributes or
  # else I would get noMethodError or something like that, I'll fix this later
  attr_accessor :username, :encrypted_password, :locked_at, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip, :sign_in_count

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :username, :password, :password_confirmation, :remember_me,
    :first_name, :last_name, :mobile_phone, :phone_one, :phone_two, :organization_id

  validates :username, :presence => true
end

现在我正在安装 Devise,它想要创建users带有email列的表。但我不想要该email列,因为 User 应该email从 Person 继承。

我希望 User 模型继承自 People 模型。人们已经有一个email属性,所以用户不再需要它。

我怎样才能让 Devise 查看表格email上的列people而不是可锁定模块的users表格,以及每当 Devise 需要发送电子邮件时

我可以email从迁移中删除该列吗?

4

1 回答 1

1

要让它查找您要执行的人员电子邮件User.email,只需从设计的用户表迁移中删除该电子邮件即可。

您还需要删除电子邮件验证https://github.com/plataformatec/devise/blob/master/lib/devise/models/validatable.rb#L24

于 2012-06-27T17:04:54.567 回答