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!!
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'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With