On Feb 8, 2011, at 10:52 AM, Abu A wrote:

> Hi guys
> 
> I'm trying to upload data into the database and I've done so using paperclip. 
>  However, l am having trouble loading the contents into the database.  This 
> is my model:
> 
> import.rb:
> 
> class Import < ActiveRecord::Base
> 
>   hobo_model # Don't put anything above this
> 
>   fields do
>     datatype :string
>     abu  :string
>     paul :string
>     age :integer
>    timestamps
>   end
> 
>   # Paperclip
>           has_attached_file :csv
>           validates_attachment_presence :csv
>           validates_attachment_content_type :csv, :content_type => 
> ['text/csv','text/comma-separated-values','text/csv','application/csv','application/excel','application/vnd.ms-excel','application/vnd.msexcel','text/anytext','text/plain']
> 
> With adding <include src="paperclip" plugin="paperclip_with_hobo"/> in 
> applications.dryml, this works fine and it loads the csv file in 
> public/systems/csvs
> 
> I am having trouble using Fastercsv to load the contents into the database.  
> Anyone has done this before.  Any pointers will be appreciated.

Not sure what can really go wrong here - the docs are helpful 
(http://fastercsv.rubyforge.org/) and a typical load process is pretty 
straightforward:

class Import < ActiveRecord::Base

  def some_import_method
    FasterCSV.foreach(csv.path, :headers => true) do |row|
      # do something with row here - entries will be accessible with strings 
(not symbols!) that match the headers
    end
  end

end

I've read some reports that recent versions of Excel tend to spit out UTF-16 
formatted files, but I've not encountered that yet.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to