caxlsx / caxlsx_rails

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

Link to Remote? #92

Closed jamiebrs closed 7 years ago

jamiebrs commented 7 years ago

I am hoping this is the best place for this.

I have a link_to in that I am doing all the proper things to generate my excel. My path has x_path(format: :xlsx) and then in my controller has the

format do |format| format.xlsx end

it all works beautifully (great gem by the way)

What I want to do is add a :remote onto my link_to so that I can have some jquery that has ajax:success to fire some jquery when the spreadsheet opens (or the open as dialogue shows)

When I put the :remote on the link my jquery fires but the spreasheet never opens despite my rails console saying the xlsx.axlsx page has rendered.

What am I missing? Can this be done?

straydogstudio commented 7 years ago

If jQuery is remotely retrieving the link, it isn't necessarily going to know what to do with the data. I figure it is using turbolinks, or the like, and not finding what it expects in the response, where it would replace the contents of your page. You will need to write your own event and not use remote. I've seen various methods to make Javascript download a file. One of them is to use a hidden iframe. Change the source to your link, and the browser will take it from there. I would do a search and see what you can find.