如何将索引合并到变量名中,以便可以访问不同的组对象?
这是我的 db/seeds.rb 文件:
u = User.create( email: "yeah@foo.com", password: "yeah", password_confirmation: "yeah")
groups_list = ["Math Club", "Science Class", "Economics Class"]
groups_list.each_with_index do |name, index|
"g#{index}" = u.groups.create(name: name)
end