この場合、両方とも同じ構造locales
をaliases
共有しているため、名前だけを変更して同じ方法で繰り返します。
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
このコードを次のように単純化することを考えて[yml_site['locales'],yml_site['aliases']].each.each_value
いましたが、明らかに機能していません。どうすれば同じクエリで両方yml_site['locales']
を繰り返すことができますか?yml_site['aliases']