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 6888205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:58:54+00:00 2026-05-27T05:58:54+00:00

I am implementing in Ruby, and I just want to read in a CSV-file.

  • 0

I am implementing in Ruby, and I just want to read in a CSV-file. My CSV looks like :

"official_code","username","lastname","firstname","email","Course Groups","password"
"1626","000078sr","LENS","Ser","blab@hogent.be","project1g43","pwd7975"
"7334","000116jd","DE ","Joen","je0116@.hogent.be","project1g08","pwd5259"
"2003","000136bv","VACKE","Bert","hogent.be","project1g18","pwd5908"
"4065","000166cr","ROHøJ","Chrian","chrhogent.be","project1g10","pwd5000"

It is made in Excel and set in a CSV-file

But when I do in my application:

 FasterCSV.foreach(file.path, {:headers=>true }) do |row|

            @samples[i] = row
      i += 1
    end # do

 if @samples.size > 0
      @headers = @samples[0].headers
    end 

and in my view I just do:

<%= @headers.inspect %>


<ul>
<% @samples.each do |a| %>
<li>
<%= a %>
</li>
<% end %>
</ul>

I get:

["\"official_code\",\"username\",\"lastname\",\"firstname\",\"email\",\"Course Groups\",\"password\""]

"""1626"",""000078sr"",""ENS"",""Sder"",""san.hogent.be"",""project1g43"",""pwd7975"""
"""7334"",""000116jd"",""DE VOS"",""Jen"",""jeroen.ogent.be"",""project1g08"",""pwd5259"""
"""2003"",""000136bv"",""VYCKE"",""Bet"",""berent.hogent.be"",""project1g18"",""pwd5908"""
"""4065"",""000166cr"",""ROøJ"",""Chstian"",""chr.hogent.be"",""project1g10"",""pwd5000"""

So there are way to many ” ‘s. Does someone know what I am doing wrong? It is just like rows only have 1 column. If I do samples[0].each I get only 1 item. The whole row and not the columns.

  • 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-27T05:58:55+00:00Added an answer on May 27, 2026 at 5:58 am

    When you reference @samples you’re looking at an array of rows, each of which is an array of parsed fields.

    So when you use @samples.each do |a|, the a is a row, and I think you’re getting the result of calling #inspect on that row.

    What happens if you try something like this?

    options = { :headers=>true, :return_headers => true }
    @samples = FasterCSV.read(file.path, options).to_a
    
    if @samples.size > 0
      @headers = @samples.shift 
    end 
    

    You need :return_headers=>true if you want to get the actual labels; :headers=>true only tells FasterCSV that there are headings – it discards them by default. FasterCSV.read gets and parses all the data in one hit, which is simpler than building the array yourself. Note the to_a at the end, which forces the result to really be an array – it might make things simpler in the next part.

    What happens if you modify the view as follows (use #join instead of #inspect on the headers and add a #join on the rows)?

    <%= @headers.join(', ') %>
    
    <ul>
    <% @samples.each do |a| %>
    <li>
    <%= a.join(', ') %>
    </li>
    <% end %>
    </ul>
    

    If that doesn’t fix it, hopefully you should at least be further toward understanding what’s happening…

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

Sidebar

Related Questions

I'm implementing a small HTTP server with Ruby using Mongrel. My code currently looks
I am implementing the following problem in ruby. Here's the pattern that I want
I am implementing in Ruby on Rails, and i want to do so, that
I'm implementing a rudimentary version of LISP in Ruby just in order to familiarize
I'm implementing a loop in Ruby, but it looks ugly and I wonder if
I am currently implementing a blog-like site using Ruby on Rails. Each Post has
I'm implementing a few things in Ruby and I was wondering how much error
Does anyone know a good solution for implementing a function similar to Ruby's timeout
I need some examples of implementing curry function in ruby(1.8.6 or 1.8.7 not 1.9).
As a bit of a fun project I'm implementing a Beatnik interpreter in Ruby.

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.