ruby - FasterCSV importer to DataMapper model - No rows inserted -


I have a model (called a test):

  property: id , Serial Property: Title, String ,: Length = & gt; 255,: required = & gt; True Property: Description, String,: Length = & gt; 255,: required = & gt; True Property: Brand, String,: Length = & gt; 255,: required = & gt; Real Property: Link, String, Length = & gt; 255,: required = & gt; Real Property: image_link, string,: length = & gt; 255,: required = & gt; True Property: Value, String ,: Length = & gt; 255,: required = & gt; True Property: Condition, String,: Length = & gt; 255,: required = & gt; True Property: Product_type, String,: Length = & gt; 255,: required = & gt; True  

I am importing data from a tab delimited file, using the FORTRCO CSV,

FasterCSV.foreach ("test.txt", {: Headers => true,: quote_char => '' ':: col_sep =>' / t '}) do | Row_data | Status, Provider, 'Brand' = & gt;

Gt;: brand, 'link' =>: link, 'image_link' =>: image_link, 'price' => 'product_type' = & gt ;: product_type)

row_data.save

termination

No imported when an error occurs. Inserted in the SQLite table.

Am I missing something clear? (The table is present within the target database, and the field names are same as the headings of my file.

< Strong> Update 2014/11/19: Sharp CSV has been deleted: Ruby Standard Library CSV should now be used in the internet. Just replace all the events FasterCSV with CSV < / Code>

Two problems I think

  • The delimiter you use instead of "\ t" to
  • < Li> you data

This should work better:

  FasterCSV .foreach ("test.txt" , {: Headers = & gt; true: quote_char = & gt; ",: col_sep = & gt;" \ t "} do | row_data | new_record = test.first_or_new ('title' = & gt; line_data ['Title'], 'Description' = & gt Row_data ['Supplier'], 'Brand' = & gt; Line_Data ['Brand'], 'Link' = & gt; Line_data ['Link'], 'Image_Link' = & Gt; row_data ['image_link'], 'value' = & gt; Row_data ['price'], 'condition' = & gt; Row_data ['condition'], 'product_type' = & gt; Row_data ['product_type']) new_record.save end  

Comments