Sha256: 7c9367a6ebe9a1cb73f91fd1e2e5ae3ec577a47ac65457bcca57b239e95e9ce1
Contents?: true
Size: 433 Bytes
Versions: 29
Compression:
Stored size: 433 Bytes
Contents
class JsonValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) record.errors[attribute] << (options[:message] || I18n.t("slash_admin.view.json_not_valid")) unless valid_json?(value) end def valid_json?(string) # handle parsed already string if string.is_a? Hash return true end begin !!JSON.parse(string) rescue JSON::ParserError false end end end
Version data entries
29 entries across 29 versions & 1 rubygems