Ran into an issue with a rails 3.0 app which I had running on ruby 1.9 and am now getting to run on ruby 1.8. The app pulls in data from some CSV files and used the CSV library in ruby 1.9. All the CSV data imports failed under ruby 1.8. A little research showed that this is because CSV in ruby 1.9 was FasterCSV in ruby 1.8, and the CSV class in ruby 1.8 was something completely different. So I got around this by doing the following:
Add a conditional include of fastercsv to the Gemfile:
gem 'fastercsv', :platforms => :ruby_18
And then where I want to perform CSV operations, I do the following:
if CSV.const_defined? :Reader
csv = FasterCSV
else
csv = CSV
end
csv.foreach(path) do |row|
...
end
Thanks to http://blog.grayproductions.net/articles/getting_code_ready_for_ruby_19 for the conditional.
Also handy, since the app is running on both windows and linux was the following:
path = File.join(CSV_PATH, 'file.csv')
Hope this helps.
Just what I needed. I was reverting back from MRI 1.9 to REE 1.8 to do some performance testing and this would have given me fits otherwise!
Thanks,
shakerlxxv
http;//4-dogs.biz
Glad it was useful for someone!
Hello Jeff,
I am an Information Technology student that is currently enrolled at British Columbia's Institute of Technology. In regards to that, I am currently in my second year and have come across a ROR-related problem that you may be able to help me with. My team and I are involved in a project that requires us to develop a dynamic form builder in which users will be able to create customized forms that will meet their specific needs.
My team has completed a majority of the form functionality but one key feature has provided us with trouble. The data held in the our "form results" table must be given the ability to be downloaded in CSV format. I am currently running Ruby 1.9.2 with Rails 3 and I'm doing my development on Ubuntu via VM.
I have honestly looked everywhere and tried to implement a majority of examples using FasterCSV but haven't had any success. I heard FasterCSV isn't compatible with Ruby 1.9.2 but that could be a misunderstanding. Our project is due in a week and a half and I didn't know where else to turn. If you have any knowledge, advice or resources that would help my team and I, we would be forever grateful.
Thank you for your time,
Maz M.
Matz,
Sorry about the slow reply. Are you still having issues? Post some code and I'll help you as best I can.
Jeff