I use HStore in Rails 4.1 to manage I18n and storage of languages. It works great the only problem I have is I would like to do something like this (instead of using store_accessor)
In Rails 4.0 this worked great:
https://gist.github.com/rf-/2322543 (simple_form and hstore basic functionality)
So I could simple do something like:
validates_hstore :content do
validates_presence_of :en
end
Where the magic happened (doesn't seem to work correctly in Rails 4.1)
module HstoreValidation
def validates_hstore(field, &block)
validation_class = Class.new do
include ActiveModel::Validations
def self.name
'(validations)'
end
def initialize(data)
@data = data
end
def read_attribute_for_validation(attr_name)
@data[attr_name]
end
end
validation_class.class_eval &block
validate do
validator = validation_class.new(self[field])
if validator.invalid?
validator.errors.each do |attr, text|
self.errors.add(attr, text)
end
end
end
end
end
Instead i always get, even when the field is not blank:
messages:
:en:
- can't be blank