views:

210

answers:

1

A user can import data into our website from a file. The data normally contains several hundred Items (Item < ActiveRecord::Base).

Although the validations help, they cannot solve the problem of sanity-checking the content. For that we would like to have a test mode.

Could we use a temporary Items table for this with Rails/MySQL, and, if yes, how should we do it?

+3  A: 

You can use AR Extensions gem for this. Read this article for more details.

User.create_temporary_table do | temp_model|
  # now perform the inserts on temp table.
  temp_model.create(...)
  ...
end # table dropped automatically 

OR

temp_model = User.create_temporary_table
temp_model.create(...)
#do something
...
...
#drop the temp table
temp_model.drop
KandadaBoggu