Tuesday, April 15, 2008

Equipment imported!

Finally! I've actually imported a csv file of equipment records into the database. There were some gotchas with the csv -- but I created a plugin called load_dump to add yaml import/export and csv import for models. The plugin adds the import/export actions to the controller and is used this way:

generate_load_dump_actions_for

Example:

generate_load_dump_actions_for Inventory

That's all there is to it. Then in the view, you have to create a form and links for the csv and yaml actions, respectively:


= "| #{link_to 'Export Yaml', dump_models_path(:controller => 'equipmentis')}" if @equipmentis.length > 0
= "| #{link_to 'Import Yaml', load_models_path(:controller => 'equipmentis')}" if @equipmentis.length == 0


.form_container
- error_handling_form_for :dump, :url => {:controller => controller, :action => 'load_model_from_csv'}, :html => {:multipart => true} do |f|

%fieldset
%legend Import CSV
= f.file_field :file, {:label => 'Select a CSV file', :message => '(make sure first row has headers)'}
= f.submit 'Import'

0 comments: