레일 3.1을 사용하고 있습니다.레일 : attr_accessor의 validates_numericality_of가 예상대로 작동하지 않습니다.
class Product < ActiveRecord::Base
attr_accessor :output_unit
...
validates_numericality_of :output_unit, greater_than_or_equal_to => 0, :on => update
...
end
나는 제품을 업데이트하려고 내가이 분야에 다수 소개, 양식 메시지 표시 "출력 단위는 숫자가 아닌":이 같은 모델 제품 무언가가있다.
고맙습니다. 당신은 방법 output_unit_before_type_cast
를 작성하고 self.output_unit
를 반환 할 수 있습니다
데이터베이스에서 "output_unit"의 데이터 유형은 무엇입니까? (예 :'db/schema.rb'에 표시) – lurker
이 속성은 데이터베이스에 저장되지 않고 가상 속성입니다. –