Guest User

Untitled

a guest
Mar 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. def add_multiple_associated_save_callbacks(association_name)
  2. method_name = "validate_associated_records_for_#{association_name}".to_sym
  3. define_method(method_name) do
  4. association = instance_variable_get("@#{association_name}")
  5. if association.respond_to?(:loaded?)
  6. if new_record?
  7. association
  8. else
  9. association.select { |record| record.new_record? } # **** this one ****
  10. end.each do |record|
  11. errors.add "#{association_name}" unless record.valid?
  12. end
  13. end
  14. end
Add Comment
Please, Sign In to add comment