Reputation: 3
I have a strange error if I try to create a new model-object. The strange thing is that the column in the error message is not available in the database. This is what I did:
My console-output:
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'
My rails model:
class OZBPerson < ActiveRecord::Base
self.table_name = "ozbperson"
self.primary_key = :Mnr
attr_accessible :Mnr,
:UeberPnr
end
My db-table:
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,
There is no such field like "email", but I still get this error message. What is wrong?
Upvotes: 0
Views: 142
Reputation: 19314
If you are using devise, add this to your model
def email_required?
false
end
It overrides what currently exists in the devise model which is true.
Upvotes: 1
Reputation: 2891
I'm guessing this is because you are using devise. Devise's requires an email field so methods like its reset_password_token (where attempts to find users by their email) can work. If you are not using devise ignore this answer, otherwise you'll need to add email to your person.
Upvotes: 0