In this case, both locales and aliases share the same structure and so I iterate them in the same way changing only its name.
if yml_site['locales'].present?
yml_site['locales'].each_value do |yml_locale|
site = Site.find_or_create_by_domain(
locale: yml_locale['locale'],
domain: yml_locale['domain'],
title: yml_locale['title'],
parent: yml_site['domain'],
end
end
if yml_site['aliases'].present?
yml_site['aliases'].each_value do |yml_alias|
site = Site.find_or_create_by_domain(
locale: yml_alias['locale'],
domain: yml_alias['domain'],
title: yml_alias['title'],
parent: yml_alias['domain'],
end
end
end
I was thinking to simplify this code with something like [yml_site['locales'],yml_site['aliases']].each.each_value but obviusly its not working. Any idea how can I iterate both yml_site['locales'] and yml_site['aliases'] on the same query ?
How about this: