Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails中的ghost db列。未定义的方法“email';_Ruby On Rails_Ruby_Database_Rails Activerecord - Fatal编程技术网

Ruby on rails rails中的ghost db列。未定义的方法“email';

Ruby on rails rails中的ghost db列。未定义的方法“email';,ruby-on-rails,ruby,database,rails-activerecord,Ruby On Rails,Ruby,Database,Rails Activerecord,如果我尝试创建一个新的模型对象,我会出现一个奇怪的错误。奇怪的是,错误消息中的列在数据库中不可用。 这就是我所做的: 我的控制台输出: 1.9.3p286 :002 > person = OZBPerson.new => #<OZBPerson Mnr: nil, UeberPnr: nil, Passwort: nil, PWAendDatum: nil, Antragsdatum: nil, Aufnahmedatum: nil, Austrittsdatum:

如果我尝试创建一个新的模型对象,我会出现一个奇怪的错误。奇怪的是,错误消息中的列在数据库中不可用。 这就是我所做的:

我的控制台输出:

1.9.3p286 :002 > person = OZBPerson.new
     => #<OZBPerson Mnr: nil, UeberPnr: nil, Passwort: nil, PWAendDatum: nil, Antragsdatum: nil, Aufnahmedatum: nil, Austrittsdatum: nil, Schulungsdatum: nil, Gesperrt: 0, SachPnr: nil, encrypted_password: "$2a$10$...", 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> 
1.9.3p286 :003 > person.valid?
    NoMethodError: undefined method `email' for #<OZBPerson:0x007ffd2b30dee8>
        from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/activemodel-3.2.3/lib/active_model/attribute_methods.rb:407:in `method_missing'

没有像“email”这样的字段,但我仍然收到这个错误消息。怎么了?

我猜这是因为您使用的是Deave。Deviate需要一个email字段,这样它的reset_password_令牌(试图通过电子邮件找到用户的地方)等方法就可以工作。如果您没有使用Deviate,请忽略此答案,否则您需要向您的个人添加电子邮件。

如果您使用Deviate,请将此添加到您的模型中

def email_required?
    false
end

它覆盖了Desive模型中当前存在的事实。

这一点很好,我投了你一票。我也应该建议的!我只是想,如果他正在使用Deviate,他可能想利用它的可确认/可恢复/etc功能。我认为你只能用一种或另一种方式使用它——要么让email字段作为唯一标识符,要么使用可确认/可恢复/etc,或者删除电子邮件唯一标识符并失去使用confirmable/recoverable/etc的能力。这就是我的意思:)我没有列出所需的电子邮件?选项,因为我不知道如果你不想使用所有需要电子邮件的功能,为什么要添加Desive这样一个大型库。事实上,我昨晚为一个项目做了同样的事情。基本上,我有一些用户将其他用户添加到应用程序中。他们希望能够添加没有电子邮件地址的孩子,所以我必须添加相同的代码,这样就不会因为没有电子邮件地址而崩溃。无论如何,这就是我的用例。我已经设计好了,它为我做了所有的认证工作。这是一个简单的解决办法。是的,你是对的,这是迪安的错。我现在已恢复电子邮件列。
CREATE TABLE `ozbperson` (
`Mnr` int(10) unsigned NOT NULL,
`UeberPnr` int(10) unsigned DEFAULT NULL,
`Passwort` varchar(35) DEFAULT NULL,
`PWAendDatum` date DEFAULT NULL,
`Antragsdatum` date DEFAULT NULL,
`Aufnahmedatum` date DEFAULT NULL,
`Austrittsdatum` date DEFAULT NULL,
`Schulungsdatum` date DEFAULT NULL,
`Gesperrt` tinyint(2) NOT NULL DEFAULT '0',
`SachPnr` int(10) unsigned DEFAULT NULL,
`encrypted_password` varchar(64) NOT NULL DEFAULT '$2a$10$...',
`reset_password_token` varchar(128) DEFAULT NULL,
`reset_password_sent_at` datetime DEFAULT NULL,
`remember_created_at` datetime DEFAULT NULL,
`sign_in_count` int(10) DEFAULT '0',
`current_sign_in_at` datetime DEFAULT NULL,
def email_required?
    false
end