i have 3 member, answer_set, answer model_a don't have relation model_c (it's don't have directly relation. relation looklike member->answer_set->answer ),so in model_a add code save attributes on associated records
accepts_nested_attributes_for :answer_set, reject_if: :validation_method
and add reject_if method check validation of answer. answer_set attributes
def validation_method(answer_sets_attribute) question = question.find(answer_sets_attribute[:question_id]) answer = answer_sets_attributes[:answers_attributes] return true if answer[:answer_text].blank? && answer[:answer_number].blank? end but when return true validation_method it's except record not passed want return error , redirect fill form again.
finally, found solution solved problem.i used validates_presence_of :answer_set and, it'll not pass validation when accepts_nested_attributes_for rejected ,then it'll send errors validation , form.
Comments
Post a Comment