Julian
Julian

Reputation: 27

Ruby on Rails - Roo gem | Issue opening active record attachment

Status:

Issue: Roo::Excel.open() doesnt work for:

  1. Roo::Excel.open(excel)
  2. Roo::Excel.open(excel.attachment)

What is the correct command to execute to open the ActiveRecord::Attachment?

Upvotes: 0

Views: 878

Answers (2)

Julian
Julian

Reputation: 27

Actually I got an answer outside of Stackoverflow which was this:

Roo::Spreadsheet.open(ActiveStorage::Blob.service.path_for(excel.key), extension: 'xlsx')

I loaded one row from the Excel so must change code but opening it seemed to have worked! :-)

Upvotes: 1

Dedy Puji
Dedy Puji

Reputation: 625

how about do this?

ModelName.excel.open do |file|
 xlsx = Roo::Spreadsheet.open(file)
end

Upvotes: 1

Related Questions