用户可以将数据从文件导入我们的网站。 数据通常包含几百个项(item<activerecord::base)。
尽管验证有帮助,但它们无法解决检查内容的健全性问题。 为此,我们希望有一个测试模式。
我们可以在rails/mysql中使用一个临时的items表吗?如果可以,我们应该怎么做?
你可以使用 AR Extensions 这是宝石。读这个 article 更多细节。
User.create_temporary_table do | temp_model| # now perform the inserts on temp table. temp_model.create(...) ... end # table dropped automatically
或
temp_model = User.create_temporary_table temp_model.create(...) #do something ... ... #drop the temp table temp_model.drop