app/models/batch.rb
# Validate the associated tickets and add validation errors if needed.
Validate the associated tickets and add validation errors if needed.
Validate the associated tickets and add validation errors if needed .
def validate_tickets
    if self.errors[:tickets]
      self.instance_variable_get(:@errors).delete(:tickets)
      self.tickets.each do |ticket|
        next if ticket.valid?
        self.errors.add(:base, "Ticket with address '#{ticket.email}': " + ticket.errors.full_messages.join(', '))
      end
    end
  end
def validate_tickets if self . errors [ :tickets ] self . instance_variable_get ( :@errors ) . delete ( :tickets ) self . tickets . each do | ticket | next if ticket . valid? self . errors . add ( :base , "Ticket with address '#{ticket.email}': " + ticket . errors . full_messages . join ( ', ' ) ) end end end
Validate the associated tickets and add validation errors if needed.
Validate the associated tickets and add validation errors if needed .
# NOTE: This strange method is run at the end of validation and replaces # the vague "Tickets is invalid" validation error with more useful messages # that explain what tickets had what errors.