我有以下型号
class User < ActiveRecord::Base
VALID_EMAIL_REGEX = /^.+@.+\..+$/i
attr_accessible :active_list_id, :password, :password_confirmation, :email, :temp
has_secure_password
before_create { generate_token(:auth_token) }
if :temp.nil?
before_validation :downcase_email
validates_presence_of :email, :password, :password_confirmation, :on => :create
validates_confirmation_of :password
#something@something.something
validates :email, :uniqueness => true,
:format => {:with => VALID_EMAIL_REGEX }
end
after_create { make_list([email,"'s shopping list"].join('')) }
has_many :shopping_lists
has_many :transactions, :class_name => 'Order'
HUMANIZED_ATTRIBUTES = {
:password_digest => "Password"
}
...
end
我尝试通过调用User.create(:temp => true)
(这是一个布尔值,在我的迁移/模式中定义)在我的 Rails 控制台中创建一个模型。但它总是回滚事务。我究竟做错了什么?
我还尝试对我的所有 3 个验证进行:if => temp.nil?
andif => "temp.nil?"
和 and :if => lambda { |user| user.temp.nil? }
。