title: Rails - Can't import data from CSV file
body: <p>I am trying to import data from a CSV file, I don't want to save the file. I have found a similar question here: <a href="https://stackoverflow.com/questions/4410794/ruby-on-rails-import-data-from-a-csv-file">Ruby on Rails - Import Data from a CSV file</a></p>
  
  <p>However, when I try and use this solution I get an error.</p>
  
  <p>My Form is as follows:</p>
  
  <pre><code>Import a CSV file
  &lt;%= file_field_tag :file %&gt;
  
  &lt;div class="actions form-group" id="button_text"&gt;
  &lt;p&gt;
  &lt;%= button_tag(type: 'submit', class: "btn btn-primary button-submit") do %&gt;
  Submit
  &lt;% end %&gt;
  </code></pre>
  
  <p>On the new page the submission of this form calls the create action, the create action then calls the line: </p>
  
  <pre><code>Product.import(params[:file])
  </code></pre>
  
  <p>I have the following import method in my model:</p>
  
  <pre><code>def self.import(myfile)
      require 'csv'    
  
      csv_text = File.read(myfile)
      csv = CSV.parse(csv_text, :headers =&gt; true)
      csv.each do |row|
  
      end
  end
  </code></pre>
  
  <p>where 'myfile' is params[:file].</p>
  
  <p>I am aware I am not doing anything with the data yet. I am getting an error with line <code>csv_text = File.read(myfile)</code> which is: No such file or directory @ rb_sysopen - X.csv</p>
  
  <p>When looking for a solution I have seen .path is used. If i change this line to <code>csv_text = File.read(myfile.path)</code> I get the error: undefined method `path' for "X.csv":String</p>
  
  <p>Can anybody help? I feel like I must be very close to a solution but I just keep going round and round between these two errors. Is it possible to get the data from the csv without saving it first?</p>
  
  <p>Thanks for your time</p>