Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save visnup/38554 to your computer and use it in GitHub Desktop.
Save visnup/38554 to your computer and use it in GitHub Desktop.
validates_length_of_less_than_max_allowed_packet
def self.max_allowed_packet
r = connection.execute "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'"
r.fetch_row.last.to_i rescue 128.megabytes
end
validates_length_of :data, :in => 1 .. max_allowed_packet,
:allow_blank => true
validates_length_of :file, :in => 1 .. max_allowed_packet,
:allow_blank => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment