mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
Drop Rails3 support
This commit is contained in:
@ -3,23 +3,17 @@
|
||||
class IpAddressFormatValidator < ActiveModel::EachValidator
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
if rails4?
|
||||
# In Rails 4.0.0, ip_address will be nil if an invalid IP address was assigned.
|
||||
# https://github.com/jetthoughts/rails/commit/0aa95a71b04f2893921c58a7c1d9fca60dbdcbc2
|
||||
# In Rails 4.0.0, ip_address will be nil if an invalid IP address was assigned.
|
||||
# https://github.com/jetthoughts/rails/commit/0aa95a71b04f2893921c58a7c1d9fca60dbdcbc2
|
||||
|
||||
# BUT: in Rails 4.0.1, validators don't get a chance to
|
||||
# run before IPAddr::InvalidAddressError is raised.
|
||||
# I don't see what broke it in rails 4.0.1...
|
||||
# So this validator doesn't actually do anything anymore.
|
||||
# But let's keep it in case a future version of rails fixes the problem and allows
|
||||
# validators to work on inet and cidr columns.
|
||||
if record.ip_address.nil?
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
else
|
||||
unless !record.ip_address.nil? and record.ip_address.to_s.split('/').first =~ Resolv::AddressRegex
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
# BUT: in Rails 4.0.1, validators don't get a chance to
|
||||
# run before IPAddr::InvalidAddressError is raised.
|
||||
# I don't see what broke it in rails 4.0.1...
|
||||
# So this validator doesn't actually do anything anymore.
|
||||
# But let's keep it in case a future version of rails fixes the problem and allows
|
||||
# validators to work on inet and cidr columns.
|
||||
if record.ip_address.nil?
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user