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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:37:05+00:00 2026-06-07T23:37:05+00:00

When I want to select a file via file_field, it gives me the error

  • 0

When I want to select a file via file_field, it gives me the error that my file is ‘nil’. Here’s the error: “No such file or directory – Book1.csv”

May I know why? Below are the codes:

controller

def import_csv
@list = List.find(params[:list_id])
@lists = List.all

respond_to do |format|

@csv_text = File.read(params[:list][:file])
@csv = CSV.parse(@csv_text, :headers => true)
@n=0
@csv.each do | row |
  @user_new = User.new
  @user_new.first_name = row[0]
  @user_new.last_name = row[1]
  @user_new.email = row[2]
  @user_new.company = row[3]
  @user_new.address = row[4]
  @user_new.city = row[5]
  @user_new.state = row[6]
  @user_new.zipcode = row[7]
  @user_new.country = row[8]
  @user_new.notes = row[9]
  @user_new.birthday = row[10]
  @user_new.home_number = row[11]
  @user_new.mobile_number = row[12]
  @user_new.list_id = @list.id
  @user_new.save

  @list.subscribers += 1
  @list.save
  @n=@n+1
  GC.start if @n%50==0
  flash[:notice] = "CSV Imported Successfully, with  #{@n} records"                                
end

  format.html { redirect_to lists_url }
  format.json { head :no_content }
end
  end

view

<%= form_for(:list, :url => list_import_csv_path(@list), :method => :get, :html => {:multipart => true}) do |f| %>
 <table>
    <tr>
        <td><label for="dump_file">Select a CSV File :</label></td>
        <td><%= f.file_field :file %></td>
    </tr>
    <tr>
        <td colspan='2'><%= submit_tag 'Import from CSV file' %></td>
    </tr>
</table>
<% end %>
  • 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-06-07T23:37:06+00:00Added an answer on June 7, 2026 at 11:37 pm

    This is because you try to pass the ActionDispatch::Http::UploadedFile Object as a path instead of the real path. You do:

    @csv_text = File.read(params[:list][:file])
    

    you should do:

    @csv_text = File.read(params[:list][:file].tempfile.to_path.to_s)
    

    Also it might be a problem that you use :method => :get when you upload not so tiny files. Genereally GET and File Upload arent such a great combination.^^

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

Sidebar

Related Questions

I want to select line of a file where the absolute value of column
I want to select urls with pdf file extension and list the pdfs separately,
I want to go to select a file from sdcard and upload it to
I have Uitable with data read from a AScii file. I want to select
I want to enable the user to select a video file from the on-device
I have an XML file that i access via an URL. Is it possible
I want to auto select a file through File input tag < input type=file
When a user selects a file, I want another file field to appear. It
I want to reset a file upload field when the user selects another option.
i have users table and i have posts table i want select from users

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.