Ruby Error

ActiveRecord::RecordInvalid

ActiveRecord::RecordInvalid is raised when calling save!, create!, or update! on a record that fails validation. The bang methods raise exceptions instead of returning false.

Common causes

  • Missing required attributes (presence validation)
  • Invalid format (email, phone, etc.)
  • Uniqueness constraint violation
  • Custom validation failures
  • Association validation failures

How to fix it

  • Use save/create/update (without bang) and check return value
  • Validate data before attempting to save
  • Check record.errors for specific validation messages
  • Rescue the exception and handle gracefully
  • Display validation errors to users in forms

Example

ActiveRecord::RecordInvalid example
# Error example
user = User.new(email: "invalid")
user.save!  # => ActiveRecord::RecordInvalid: Validation failed: Email is invalid

# Fix by checking save result
user = User.new(email: "invalid")
if user.save
  # success
else
  puts user.errors.full_messages
end

# Or rescue the exception
begin
  user.save!
rescue ActiveRecord::RecordInvalid => e
  logger.error("Validation failed: #{e.record.errors.full_messages}")
end

Track ActiveRecord::RecordInvalid with Checkend

Checkend automatically captures ActiveRecord::RecordInvalid errors in your Ruby application with full context:

  • Complete backtrace with syntax highlighting
  • Request context (URL, params, headers)
  • Automatic grouping of similar errors
  • Instant notifications when errors occur

Stop debugging in production

Get full error context and fix issues faster with self-hosted error tracking.