Reputation: 1180
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 %>
Upvotes: 1
Views: 2169
Reputation: 1180
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)
Upvotes: 2