I'm trying to add validations to my mobility-powered application and i'm confused a little.Earlier I've used code like this
I18n.available_locales.each do |locale|
validates :"name_#{locale}", presence: true, uniqueness: {scope: :animal_type}
end
And it worked fine. But in my last project it doesn't work at all. Any ideas how to perform validations? My config is below:
Mobility.configure do
plugins do
backend :container
active_record
reader
writer
backend_reader
query
cache
presence
locale_accessors
end
end
UPD: I've identified my problem - it is because of , uniqueness: {scope: :animal_type}
. Is it possible to use mobility with similar type of validations?
When you use
uniqueness
validator it uses query to the database to ensure that record haven't already taken and you get this query:Let's assume you have
Animal
modelAnd of course there is no
name_en
field in theanimals
table that is why you have an errorTo archive this you have to write your own validator
And then in your model do next: