我有一个有 5 个水果的用户模型:
User
fruit_1
fruit_2
fruit_3
fruit_4
fruit_5
插入用户模型时是否可以进行 for-each?喜欢
@fruits = ['apple','banana','orange','strawberry','blueberry']
user = User.new
@fruits.each do |a, fruit |
user.fruit_a = fruit <-- I want a to be the actual variable.
end