oh, it works if you reject the creation of the third-level nested model in the second-level nested model.
On May 7, 4:46 pm, Fattah <[email protected]> wrote: > You can write method to validate nested result attributes. > > Def valid_nested_results?(results_attributes) > > results_attributes.each do|res_attr| > return false if(res_attr['attr1'].blank? and res_attr['attr2'].blank? ....) > end > > return true > > end > > And use this method in reject_if instead of > attributes['results_attributes'].blank? > > Or you can also define the appropriate :reject_if for nested attribute > definition for results in treatment model. > > Does it help? > > -----Original Message----- > From: Mlle <[email protected]> > Sent: Friday, 7 May 2010 7:35 PM > To: Ruby on Rails: Talk <[email protected]> > Subject: [Rails] Reject a nested object if all parameters of its own nested > object are blank > > Hello, > > I have a model called Sample that has many Treatments. A Treatment > can have many Results. > > I want to reject the creation of a Treatment if all its fields are > blank and if all the fields of each of its nested Results are blank. > > I have this in the Sample model: > > accepts_nested_attributes_for :treatments, :allow_destroy => > true, :reject_if => proc { |attributes| > attributes['treatmenttype'].blank? && attributes['author'].blank? && > attributes['results_attributes'].blank? } > > This part: > attributes['results_attributes'].blank? > > only makes it reject the Treatment if there are no Results, but how > can I write the conditions so that it will reject the creation of a > Treatment if all the attirubtes of each Result are blank? Right now > it creates the Treatment if the Result exists, regardless of whether > all its fields are blank. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

