我有以下方法:
def self.get_rec(product, type)
if type == "A"
db = Pwvav
elsif type == "B"
db = Pwbab
elsif type == "C"
db = Pwvub
else type == "D"
db = Tic
db.find_by_id(product.id).recommendation.split(",").each do |rec|
r = Recommendation.find_by_id(rec)
pr = Model.new(:rating_set => rating_set.id, :recommendation_id => r.id, :product_id => product.id)
pr.save
end
end
end
当我运行该方法时,db.find
它没有按我预期的那样工作。如果替换db.find_by_id(product.id).recommendation.split(",").each do |rec|
为Pwvav.find_by_id(product.id).recommendation.split(",").each do |rec|
例如,它可以工作。如何根据type
等号选择要调用的模型?