0
好,所以我有字符串“产品”。调用新的db字符串名称
table_name = "Product"
我不能做
table_name.new
undefined method `new
,所以我试图找到一个变通这样
table_name = table_name.downcase.pluralize
name = ActiveRecord::Base.connection.tables.select { |t| t == table_name }.first
name.new
我不知道这会工作,但即使它看起来像一个黑客,任何想法来清理这个
想通了 EVAL “实例=#{} table_name的。新型” – Trace 2010-08-29 18:13:20
我建议使用constantize代替。 – 2010-08-29 23:23:36