Hello all,
I have a user that will be importing csv files occasionally. I have,
with a great amount of help (thanks James), set up an app. that will
read a csv and save to database.
I need to check for duplicate records before writing to database.
I'm thinking about putting a conditional to check for the duplicates via
column name.
- In controller -
Irb.transaction do
FasterCSV.parse(file,
:headers => true,
:header_converters => lambda { |h| h.tr(" ",
"_").delete("^a-zA-Z0-9_")},
:converters => :all ) do |row|
# I'm thinking conditional looping thru the Model
here. #
Irb.create!( {"reconciled" => 0,
"non_related" => 0
}.merge(row.to_hash))
rowcount += 1
end
end
The validation works as it should but it stops the process of importing
the file. I would have to clean the csv of duplicate records before the
import.
The validation works as it should but it stops the process of importing
the file. I would have to clean the csv of duplicate records before the
import.
create() fails silently, returning the unsaved database object with errors if it could not be written to the database for some reason. create!() raises an error under the same circumstances.
James Edward Gray II
···
On Feb 4, 2010, at 2:08 PM, John Mcleod wrote:
Not to move away from this discussion but what's the difference between
"create" and "create!" ?