Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1041825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:24:44+00:00 2026-05-16T15:24:44+00:00

Ok so I am trying to import a csv which I need to insert

  • 0

Ok so I am trying to import a csv which I need to insert into a db through rails or anyway that would be quickest so i decided to create a dummy rails application to do the importing. Here is some of the code below which I got some of it from a blog I was reading.

def upload
  table = ImportTable.new :original_path => params[:upload][:csv].original_path
  row_index = 0    
  FasterCSV.parse(params[:upload][:csv]) do |cells|

  column_index = 0
  cells.each do |cell|
    table.import_cells.build :column_index => column_index, :row_index => row_index, :contents => cell
    column_index += 1
  end
  row_index += 1
end
  table.save
  redirect_to import_table_path(table)
end

All works well but the format of the csv is not in a way that is making this process easy. Here is the format and what i need to happen.

NELCO 2GB RAM, 250GB HDD, DVD-RW, WIN7 PRO / XP LOADED  $575.00     1   $575.00     2   $1,150.00   3   $1,725.00   4   $2,300.00   5   $2,875.00 
TOUCHSCREEN, 15" LCD, SPKRS     $489.00     1   $489.00     2   $978.00     3   $1,467.00   4   $1,956.00   5   $2,445.00 
THERMAL RECEIPT PRINTER FRONT LOADING   $324.00     1   $324.00     2   $648.00     3   $972.00     4   $1,296.00   5   $1,620.00 
IMPACT PRINTER, SERIAL  $285.00     1   $285.00     1   $285.00     1   $285.00     1   $285.00     1   $285.00 
CASH DRAWER, 16x16  $127.00     1   $127.00     1   $127.00     1   $127.00     2   $254.00     2   $254.00 
RESTAURANTS PRO LICENSE $699.00     1   $699.00     2   $1,398.00   2   $1,398.00   2   $1,398.00   2   $1,398.00 
RESTAURANTS PRO LICENSE FOR ADDITIONAL STATIONS BEYOND 2    $535.00         $0.00       $0.00   1   $535.00     2   $1,070.00   3   $1,605.00 
CREDIT CARD PROCESSING SOFTWARE + CARD READER   $79.00  1   $79.00  2   $158.00     3   $237.00     4   $316.00     5   $395.00 
FIREWALL & STATEFUL PACKET INSPECTION   $89.00      $0.00   1   $89.00  1   $89.00  1   $89.00  1   $89.00 
STANDARD SUPPORT PLAN FIRST STATION $275.00     1   $275.00     1   $275.00     1   $275.00     1   $275.00     1   $275.00 
SUPPORT PLAN ADDT'L STATIONS    $100.00         $0.00   1   $100.00     2   $200.00     3   $300.00     4   $400.00 
PREPAID TRAINING & SUPPORT BUNDLE (1 HR.)   $89.00  1   $89.00  1   $89.00  1   $89.00  1   $89.00  1   $89.00 

Sorry if its hard to read i did my best at formatting. The first element in each row is the name of the product so i need that stored in Product.name and the second is the price so that will go in Product.price. the next one is where i am having problems

in the loop

      cells.each do |cell|

I need to check to see if I am at the third element in the row and do something and the fifth element and do another thing but i tried cell[2] and got something funky like this

    Rails.logger.info "====3rd postion==========#{cell[3]}"
  =>    ====3rd postion===========79
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:24:44+00:00Added an answer on May 16, 2026 at 3:24 pm

    Are you intending to actually do cells[3] instead of cell[3]? cell is a string and not an array. Depending on which version of ruby you’re using, cell[3] will either be an integer representing the ascii character, or the 2nd character in the string.

    http://ruby.about.com/od/newinruby191/qt/stringindexop.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Microsoft Access database query that I'm trying to import into a
I'm trying to insert some import lines into a python source file, but i
I am trying to import a .csv file into a table. I have figured
I have some CSV data files that I want to import into mySQL. I
I'm trying to create an import program from CSV. My code is csv =
I am trying to insert a .csv file into SQL Server 2008 R2. The
I'm trying to write an import rakefile for Redmine. It uses ruby on rails.
I'm trying to import a large number of products from a DB into Magento.
So I'm trying to import some sales data into my MySQL database. The data
I'm trying to use Ruby's csv module to import the records contained in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.