Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

roo gem file .xlsx does not exist

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!!

like image 238
Hyung Kyu Park Avatar asked Aug 27 '15 15:08

Hyung Kyu Park


1 Answers

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'))
like image 114
K M Rakibul Islam Avatar answered Oct 21 '22 03:10

K M Rakibul Islam