multilang-hstore icon indicating copy to clipboard operation
multilang-hstore copied to clipboard

validate all locales rather than specific locale

Open wingleungchoi opened this issue 10 years ago • 4 comments

multilang :content, :required => [:en]

The above validation will validate all locales rather than just :en.

I think line70 is the reason why it happens

In active_record_extensions.rb#L70 # attribute presence validator if options[:required] == true or locale_required?(options[:required], locale) module_eval do validates_presence_of "#{attribute}_#{locale}" end end

wingleungchoi avatar Mar 27 '15 08:03 wingleungchoi

I'm sorry, I don't understand, can you explain it differently?

bithavoc avatar Mar 27 '15 08:03 bithavoc

Sorry about my poor english.

Here is my syntax class Sample < ActiveRecord::Base

multilang :content, :length => 500, :required => [:en]

validates :content, :any => true

end

When i try to create an instance of Sample Class, sample1 = Sample.create(content: {en: "last 4 digital number"}), i got errors @messages={:content_zh_HK=>["can't be blank"]}

I expect that it should just validate the presence of :en. However, it also validates the presence of :zh_HK.

wingleungchoi avatar Mar 27 '15 08:03 wingleungchoi

You're right, can You send me a pull request with a fix? Please include a test

bithavoc avatar Mar 27 '15 15:03 bithavoc

Sure, I am happy to help. I will try in this weekend.

wingleungchoi avatar Mar 30 '15 08:03 wingleungchoi