Rails 3.2.11、Mac OS X Mountain Lion、Ruby 1.9.3 を使用しています。
だから私はこのコードを持っています:
class Points < ActiveRecord::Base
validates :id, :presence => true
before_create :validate_points
def validate_points
if self.amount < 0
Rails.logger.error "Invalid amount of points"
else
save!
end
end
終わり
ユーザーが負の値を挿入できないように制限したい。しかし、何らかの理由で validate_points メソッドが機能しません。私が間違っていることはありますか?ありがとう。