Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
errors:
messages:
invalid_url: "is an invalid URL"
3 changes: 2 additions & 1 deletion lib/valid_url.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- encoding : utf-8 -*-
require "valid_url/engine"
require "addressable/uri"
require "resolv"

Expand All @@ -19,7 +20,7 @@ def validate_each(record, attribute, value)
end

unless !invalid && valid_scheme?(uri.scheme) && valid_host?(uri.host) && valid_path?(uri.path)
record.errors[attribute] << (options[:message] || "is an invalid URL")
record.errors.add attribute, :invalid_url, options
end
end

Expand Down
7 changes: 7 additions & 0 deletions lib/valid_url/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ValidUrl
class Engine < ::Rails::Engine
config.before_initialize do
config.i18n.load_path += Dir["#{config.root}/config/locales/**/*.yml"]
end
end
end