如果我尝试创建一个新的模型对象,我会遇到一个奇怪的错误。奇怪的是,错误消息中的列在数据库中不可用。这就是我所做的:
我的控制台输出:
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'
我的导轨模型:
class OZBPerson < ActiveRecord::Base
self.table_name = "ozbperson"
self.primary_key = :Mnr
attr_accessible :Mnr,
:UeberPnr
end
我的数据库表:
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,
没有像“电子邮件”这样的字段,但我仍然收到此错误消息。怎么了?