J
John Mcleod
Hello all,
I'm having one heck of a day.
I found out that Oracle has a identifier limit and I have several
columns that have a names longer than 30 chars.
What does this have to do with FasterCSV you ask?
I have a method in a controller that parses a .csv then writes to a
database table.
- controller -
def import_irb_file
# set file name
file = params[:irb][:file]
rowcount = 0
Irb.transaction do
FasterCSV.parse(file,
:headers => true,
:header_converters => lambda { |h| h.tr(" ",
"_").delete("^a-zA-Z0-9_")},
:converters => :all ) do |row|
Irb.create( {"reconciled" => 0,
"non_related" => 0
}.merge(row.to_hash))
rowcount += 1
end
end
# if successful then display, then redirect to index page
flash[:notice] = "Successfully added #{rowcount} IRB record(s)."
redirect_to :action => :index
rescue => exception
file_name = params[:irb]['file'].original_filename
file_parts = params[:irb]['file'].original_filename.split('.')
ext = file_parts[1]
if ext != 'csv'
error = "CSV file is required"
else
error = ERB::Util.h(exception.to_s) # get the error and HTML
escape it
end
# If an exception in thrown, the transaction rolls back and we end
up in this
# rescue block
flash[:error] = "Error adding projects to IRB table. (#{error}).
Please try again."
redirect_to :controller => 'irbs', :action => 'new'
end
If I rename several table columns, how can I skip reading the headers in
the .csv then write to the columns correctly.
I read a post that ":headers => true", allows reading the headers but
does not return them.
That's something I can use. But when I edit my csv portion to...
Irb.transaction do
FasterCSV.parse(file,
:headers => true) do |row|
Irb.create( {"reconciled" => 0,
"non_related" => 0
}.merge(row.to_hash))
rowcount += 1
end
end
I get an "Error adding projects to IRB table. (unknown attribute: Q.1B
PI8 Last). Please try again." error.
Thank you for any help with this.
JohnM
I'm having one heck of a day.
I found out that Oracle has a identifier limit and I have several
columns that have a names longer than 30 chars.
What does this have to do with FasterCSV you ask?
I have a method in a controller that parses a .csv then writes to a
database table.
- controller -
def import_irb_file
# set file name
file = params[:irb][:file]
rowcount = 0
Irb.transaction do
FasterCSV.parse(file,
:headers => true,
:header_converters => lambda { |h| h.tr(" ",
"_").delete("^a-zA-Z0-9_")},
:converters => :all ) do |row|
Irb.create( {"reconciled" => 0,
"non_related" => 0
}.merge(row.to_hash))
rowcount += 1
end
end
# if successful then display, then redirect to index page
flash[:notice] = "Successfully added #{rowcount} IRB record(s)."
redirect_to :action => :index
rescue => exception
file_name = params[:irb]['file'].original_filename
file_parts = params[:irb]['file'].original_filename.split('.')
ext = file_parts[1]
if ext != 'csv'
error = "CSV file is required"
else
error = ERB::Util.h(exception.to_s) # get the error and HTML
escape it
end
# If an exception in thrown, the transaction rolls back and we end
up in this
# rescue block
flash[:error] = "Error adding projects to IRB table. (#{error}).
Please try again."
redirect_to :controller => 'irbs', :action => 'new'
end
If I rename several table columns, how can I skip reading the headers in
the .csv then write to the columns correctly.
I read a post that ":headers => true", allows reading the headers but
does not return them.
That's something I can use. But when I edit my csv portion to...
Irb.transaction do
FasterCSV.parse(file,
:headers => true) do |row|
Irb.create( {"reconciled" => 0,
"non_related" => 0
}.merge(row.to_hash))
rowcount += 1
end
end
I get an "Error adding projects to IRB table. (unknown attribute: Q.1B
PI8 Last). Please try again." error.
Thank you for any help with this.
JohnM