Tam
Tam

Reputation: 12042

Is there a way to enforce reject_if for accep accepts_nested_attributes_for only on create?

I have something like

accepts_nested_attributes_for :questions,  :allow_destroy => true, :reject_if => lambda {|q| q[:body].blank?}

The problem is that if I want to update questions and they are empty they are rejected which means they won't be validated.

Is there a way to enforce that the reject only happens on create and not update?

Upvotes: 2

Views: 156

Answers (1)

Thong Kuah
Thong Kuah

Reputation: 3283

Perhaps a check whether the :id value is blank? If it's blank then you know that it is a create.

Upvotes: 1

Related Questions