如何在 rails 3.2 中验证全名的唯一性?
class User < ActiveRecord::Base
attr_accessible :first_name, :last_name
validates :name, :uniqueness => true
def name
[first_name, last_name].join(' ')
end
end
当我运行 rspec 时,测试失败并出现此错误。
1) User has a first name
Failure/Error: before { @user = FactoryGirl.create(:user) }
NoMethodError:
undefined method `text?' for nil:NilClass