Joined May 2014
·

Renan Mendes Carvalho

Brazil / Brasília
·
·

Posted to Validate URLs in Rails over 1 year ago

Just an idea:

require 'uri'

class UrlValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless value =~ /^#{URI::regexp}$/
      record.errors[attribute] << (options[:message] || "is not an url")
    end
  end
end
Achievements
59 Karma
0 Total ProTip Views