작성 및 업데이트 작업 중에 다른 reject_ifs가 필요합니다.RAILS 3 (중첩 된 속성)의 동작에 따라 다른 reject_ifs
:는 여기 첨부
has_many :attachments
accepts_nested_attributes_for :attachments, :allow_destroy => true, :reject_if => proc { |attributes| attributes['attachment_description'].blank? }
내가 작업 및 업데이트 작업에 대한 또 다른 특정 옵션을 생성하기위한 특정 :reject_if
옵션을 원하는 모델 ... 예를 들어
에 대한 중첩 된 속성이
업데이트 중 ...
설명이 비어 있거나 nil 인 경우 거부합니다. 파일 이름이 비어 있거나 전무 경우 만들기에
:reject_if => proc { |attributes| attributes['attachment_description'].blank? }
... 는 거부 :
:reject_if => proc { |attributes| attributes['attachment_file_name'].blank? }
나는 accepts_nested_attributes_for
블록에 :on=> :update
및 :on=> :create
을 구현하는 방법도 모르겠습니다
대안이됩니다 감사하겠습니다. 감사.
편집 :
이 방법하지만 행운을 사용하려고 노력했다.
has_many :attachments, dependent: :destroy
accepts_nested_attributes_for :attachments, :allow_destroy => true, :reject_if => proc { |attributes| attributes['attachment'].blank? }, on: :create
accepts_nested_attributes_for :attachments, :allow_destroy => true, on: :update
그것은 말한다 ...
undefined method `key?' for nil:NilClass