Question

I am having trouble importing a spreadsheet using Rails and the roo gem and keep getting a bad URI(is not URI?) error. I think this is a simple question that I just can't figure out how to do, but how do I properly upload and access the file. Here is my current code:

controller.rb

def import
    if request.post?
      Spreadsheet.client_encoding = 'UTF-8'
      xls = Roo::Spreadsheet.open(params[:file])
      p s.cell(1,1)
    end
  end

html

<%= form_tag("", method: "POST", class: 'form-horizontal', multipart: true) do %>
  <div class="form-group">
    <%= file_field_tag :file, accept: 'xls,xlsx' %>
  </div>
  <div class="form-group">
    <%= submit_tag("Import", class: 'btn btn-default') %>  
  </div>
<% end %>
Was it helpful?

Solution

What I had to do was access the path through the params file. The code is below:

Roo::Spreadsheet.open(params[:file].path, extension: :xlsx)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top