2009/8/26 John Mcleod <[email protected]>:
>
> I have this:
> imports_controller:
>
> def process_csv
>    # First thing, clear "Imports" table of data
>   �...@import = Import.find(:all)
>   �[email protected]

Just use Import.delete_all, provided you do not need any callbacks etc.
destroy only works on a single record, you are trying to use it on an
array.  You would have to do
@import.each {|i| i.destroy} or similar

Colin

>    file = params[:import][:file]
>
>    rowcount = 0
>
>    Import.transaction do
>      FasterCSV.parse(file,
>                      :headers => true,
>                      :header_converters => :symbol ) do |row|
>        Import.create!(row.to_hash)
>        rowcount += 1
>      end
>    end
>
>    flash[:notice] = "Successfully added #{rowcount} project(s)."
>
>    redirect_to :action => :process_csv
>
>  rescue => exception
>    # If an exception in thrown, the transaction rolls back and we end
> up in this
>    # rescue block
>    error = ERB::Util.h(exception.to_s) # get the error and HTML escape
> it
>    flash[:error] = "Error adding logs. (#{error}). Please try again."
>    redirect_to :action => :index
>  end
> -------------------------------------------------------------------------------
>
> When I do this I get this error...
>
> "Error adding logs. (undefined method `destroy' for #<Array:0x241d1e0>).
> Please try again."
>
> Any clues?
>
> Thanks,
>
> JohnM
>
>
> John Mcleod wrote:
>> Hello all,
>> I'm using Ruby 1.8.6 and Rails 2.3.3.
>> I'm new at Rails so bear with me, please.
>>
>> My application reads in a csv file to a staging (imports) table then
>> compares the contents of the table to a main (projects) table. Then
>> imports all non-repetitive rows to the main table.
>> This application will be used periodically.
>>
>> I know how to import the csv data to a table.
>> How do I delete all data prior to importing new data?
>>
>> Thank you for all help.
>>
>> JohnM
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to