Skip to content

Instantly share code, notes, and snippets.

@nickyp
Created July 12, 2011 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickyp/1078240 to your computer and use it in GitHub Desktop.
Save nickyp/1078240 to your computer and use it in GitHub Desktop.
validate_ip_address
def validate_ip_address
valid_ip_address = begin; IP.new(self.ip_address); rescue; end
unless ignore_nil{ valid_ip_address.is_a?(IP::V4) }
if target == "appliance"
self.errors.add_to_base I18n.t(:invalid_ipv4, :scope =>
TRANSLATE_BASE_SCOPE, :ip_address => self.ip_address)
else
self.errors.add(:ip_address, I18n.t(:invalid_ipv4, :scope =>
TRANSLATE_BASE_SCOPE, :ip_address => self.ip_address))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment