Note that there are some explanatory texts on larger screens.

plurals
  1. PORails and Importing CSV issue?
    text
    copied!<p>This seems to be a very small error but I cannot find any solution to this problem.. I am trying to use the CSV gem in my rails(3.2) application(ruby 1.9.3) and I am getting an error "NoMethodError". My controller is:</p> <pre><code>require 'csv' def import file = params[:file] &lt;-- error CSV.parse(file, :headers =&gt; false) do |row| Event.new(:Ename =&gt; row[0], :Edate =&gt; row[1], :Elocation =&gt; row[2], :Edesc =&gt; row[3], :Oname =&gt; row[4], :Oemail =&gt; row[5], :Odetail =&gt; row[6]) end end </code></pre> <p>I am getting this file from a view where the users can upload the csv file. I am getting a NoMethodError(undefined method 'nil' for nil:NilClass). My best guess is I am using this method wrong, but then my next question is how to parse the Csv data? I want to retrieve the file from my view and then parse the data into the database. How can I open the file for the same? Is the above method not correct? A quick note, I tried using the 'FasterCSV' gem but I got a "Use the standard FasterCsv 1.9.2 gem". I had to change from fastercsv to the standard csv as the gem deployment to heroku was giving a problem.</p> <p>Forgot to give the view file,</p> <pre><code>&lt;%= form_tag({:action =&gt; :import}, :multipart =&gt; true) do %&gt; &lt;%= file_field_tag 'file' %&gt; &lt;% end %&gt; </code></pre> <p>It's basic. The error I am getting is on the parse method.. I did look at the documentation and saw that I am supposed to use a string. But I thought that 'params[:file]' gives me that. Sorry, I am relatively new to Rails..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload