caxlsx / caxlsx_rails

A Rails plugin to provide templates for the axlsx gem
MIT License
735 stars 84 forks source link

Cannot generate excel on controller but works on mailer #139

Closed medinarodel closed 4 years ago

medinarodel commented 4 years ago

I have a mailer which has the functionality to email with excel attached. It is working fine.

ActionController::Base.new.render_to_string layout: false, handlers: [:axlsx], formats: [:xlsx], template: ie.template_path, locals: ie.locals

However, on the controller to download same excel file, it is not working, it is not calling my view/template (I've added pry on my view(.xlsx.axlsx))

render xlsx: ie.filename, handlers: [:axlsx], formats: [:xlsx], template: ie.template_path, locals: ie.locals

They are using same service ie = MyService.new(...)

It is not throwing any errors. Shows prompt the download, and if you download the file, it cannot be opened and is 1byte.

medinarodel commented 4 years ago

Closing this issue. My bad. If anyone who will encounter in the future. I have Rails API. This solution worked.

https://github.com/caxlsx/caxlsx_rails#using-axlsx_rails-in-api-mode