【发布时间】:2012-01-04 05:57:28
【问题描述】:
我正在尝试在测试中创建Student 记录,如下所示:
student= Student.create!(:work_phone => "1234567890")
但我收到此错误:
ActiveRecord::UnknownAttributeError: unknown attribute: work_phone
但是,work_phone 是在 Student 模型中定义的,并已迁移。
这是Studentmodel:
class Student < ActiveRecord::Base
validates_length_of :work_phone, :is => 10, :message => 'must be 10 digits, excluding special characters such as spaces and dashes. No extension or country code allowed.', :if => Proc.new{|o| !o.work_phone.blank?}
attr_accessible:work_phone
end
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails-3 activerecord rspec2