Improve character validator error messages
This commit is contained in:
parent
d73a5d4bc0
commit
56f7e692cd
2 changed files with 4 additions and 4 deletions
|
@ -3,10 +3,10 @@ class CharactersValidator < ActiveModel::EachValidator
|
|||
INVALID_URL_CHARS = "/;.,?%#".freeze
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_chars")) if value =~ /[#{INVALID_CHARS}]/
|
||||
record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_characters")) if value =~ /[#{INVALID_CHARS}]/
|
||||
|
||||
if options[:url_safe]
|
||||
record.errors[attribute] << (options[:message] || I18n.t("validations.invalid_url_chars", :invalid_url_chars => INVALID_URL_CHARS)) if value =~ /[#{INVALID_URL_CHARS}]/
|
||||
record.errors[attribute] << (options[:message] || I18n.t("validations.url_characters", :characters => INVALID_URL_CHARS)) if value =~ /[#{INVALID_URL_CHARS}]/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue