내 응용 프로그램 ActiveRecord
을 구현하지 않고, ActiveModel::Validations
와 일반 루비 클래스를 사용 :이 경우 engine
에, ActiveModel::Validations
의있는 중첩 된 속성을 확인 Car
싶습니다검증 중첩 된 모델
class Car
include ::ActiveModel::Validations
attr_accessor :engine
end
class Engine
include ::ActiveModel::Validations
attr_accessor :cylinders
validates_presence_of :cylinders
end
.
car = Car.new
car.engine = Engine.new
car.engine.valid? # => false
car.valid? # => true
# It should return 'false',
# because 'engine.cylinders' is 'nil'
이 동작을 얻는 가장 쉬운 방법은 무엇입니까?
나는 어쩌면 내가에 둥지 engine''에서 오류를 원한다고 생각했다 그런
gem 'active_type'
지금
, '자동차'의 실수지만, 대부분의 사람들이 그것이 반 패턴이라고 생각하는 것처럼 보인다. 이것은 내가 작업하고있는 기본 경우에는 충분하다고 보입니다. –