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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:01:54+00:00 2026-05-26T20:01:54+00:00

I am implementing in Ruby on Rails, and i have 2 views. In my

  • 0

I am implementing in Ruby on Rails, and i have 2 views. In my first view i read in a file and show the first rows (this works fine), then in my second view ( in the method in the controller ) i write a temporary file. Just the same. And i want to show the content of this temporary file again. But this doesn’t work, I always get the error :

IOError in Project importerController#result

closed stream

this is my code in the controller, behind the first view i do:

 tmpfile = Tempfile.new("tempfile")
    if tmpfile     
      tmpfile.write(@samples)
      tmpfile.close
      tmpfilename = File.basename(tmpfile.path)
      tmpfilenametest = tmpfilename
      if !$tmpfiles
        $tmpfiles = Hash.new
      end
      $tmpfiles[tmpfilename] = tmpfile
    else
      flash[:error] = "Cannot save import file."
      return
    end
    @path = tmpfile.path
    session[:importer_tmpfile] = tmpfilename
   end 

and then in my next view , I want to read this file by:

 tmpfilename = session[:importer_tmpfile]
      i = 0
      sample_count = 5

      if tmpfilename
      tmpfile = $tmpfiles[tmpfilename]
      if tmpfile == nil
        flash[:error] = "Tijdelijk bestand bestaat niet!"
        return
      end
    end


    fields_map = params[:fields_map]
      attrs_map = fields_map.invert

      @parsed_tempfile=CSV::Reader.parse(tmpfile)
       @sampletemp = []
     @parsed_tempfile.each  do |row| 

          @sampletemp[i] = row  

        i = i+1  

     end

In this view i just want to show it, i just have:

<ul>
<% @sampletemp.each do |x| %>
<li>
<%= x %>
</li>
<% end %>
</ul>

Does anybody see what i am doing wrong? Thanks in advance!

  • 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-26T20:01:55+00:00Added an answer on May 26, 2026 at 8:01 pm

    AFAIK, a Tempfile only lasts until you close it – then it is no longer valid. If you want to actually save data in a file that sticks around after you close it – then you’ll need to use a real File.

    Edit;
    According to our discussion, I don’t think you need a tempfile at all. You are just displaying parts of the file-data that the user has uploaded for you. You don’t need a real file object for that (tempfile or otherwise).

    The user uploads a “file” and you can parse the CSV (as you’ve done) then afterwards you can just treat it as an array of strings. Save it in an @var like “@csv_lines” and in your views access the array @csv_lines however you need to.

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

Sidebar

Related Questions

I am implementing in Ruby on Rails, and I have a view, with all
I'm implementing an application in ruby on rails (although this is a minor detail)
I am implementing in Ruby, and I just want to read in a CSV-file.
I have built a blog using Ruby on Rails. New to both. I am
I am implementing in Ruby on Rails and I am trying to work with
I am implementing in Ruby on Rails, and i want to do so, that
A little background first. I am looking into the possibility of implementing Ruby's ActiveRecord
I was implementing my first HABTM relationship and have run into an issue with
I am currently implementing a blog-like site using Ruby on Rails. Each Post has
I am implementing some ruby on rails code tweet stuff for my users. I

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.