roo gem file .xlsx does not exist
Asked Answered
W

2

6

I use cloud9 ide to use ruby on rails!

I'm testing the gem 'roo' to bring excel file to my DB. before I do it, I wanted to test this gem work.

gem doc : https://github.com/roo-rb/roo
but there is a problem to bring file!

The error message is like this

IOError in MersmapController#index

file ../assets/test.xlsx does not exist


And here is my code!

require 'roo'

class MersmapController < ApplicationController         


  def index
      xlsx = Roo::Excelx.new("../assets/test.xlsx")
      @show = xlsx.info
  end
end

and in index.erb

<h1> <%= @show %> </h1>



I test this path using my "images.jpg" (the image file)

when I write path of an image file in index.erb it definitely works!!

I tried

xlsx = Roo::Excelx.new("../assets/excel/test.xlsx")

xlsx = Roo::Excelx.new("../../app/assets/test.xlsx")

xlsx = Roo::Excelx.new("../../app/assets/excel/test.xlsx")

...... All the things!!

but finally I couldn't figure out what is the problem... I appreciate if you help me out!!

Wedekind answered 27/8, 2015 at 15:42 Comment(0)
Z
4

You can use Rails.root to get the path name of your file:

xlsx = Roo::Excelx.new(Rails.root.join('app', 'assets', 'excel', 'test.xlsx'))
Zebada answered 27/8, 2015 at 15:52 Comment(3)
In case of confusion with relative paths, you should always use absolute file path. Please consider upvoting the answer if it helped you solve your problem. Thanks :)Zebada
oh I didn't know that there is a vote system thank you!Wedekind
In my case, the excel file is uploaded with the gem CarrierWave. This is what I used, and it's working. xlsx = Roo::Excelx.new(Rails.root.join(@school.attachment.file.path))Amniocentesis
R
0

I remember that once happened to me, check if this solves your problem:

xlsx = Roo::Excelx.new(url_to_file, file_warning: :ignore)

Rivkarivkah answered 27/8, 2015 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.