I need to work with pricing data from an external vendor’s parts catalog. Is it best to create a Rails Model to represent this data or should I import it directly into the database and use pure SQL?
If a Model is the best choice, how do I import the CSV file and save objects for each record?
Any insight will be greatly appreciated.
You can use FasterCSV (included as CSV in Ruby 1.9) to parse the CSV file and create/update each record for each row in the CSV file.
If you do it this way you have the option of validating each record before you save it. If you instead do as Mischa suggested and import it in to the database and use a Rails model to represent it, you will import the data much faster but lose the ability to perform validations before inserting the data in to the database.
It is almost certainly a better idea to use a Rails model instead of pure SQL queries (which you would put where?). If you do need custom SQL queries, write them as methods (or scopes if possible) on the model.