Skip to content

Instantly share code, notes, and snippets.

View rin's full-sized avatar

Rin Raeuber rin

View GitHub Profile
@rin
rin / my_object.rb
Created April 13, 2017 11:25 — forked from anonymous/my_object.rb
Custom Validator for JSON in Rails
class MyObject < ActiveRecord::Base
class JsonValidator < ActiveModel::EachValidator
def initialize(options)
options.reverse_merge!(:message => :invalid)
super(options)
end
def validate_each(record, attribute_before_typecast, value)
attribute = attribute_before_typecast.to_s.sub('_before_type_cast', '')
value = value.strip if value.is_a?(String)

My Atom config