Closed gwalther closed 8 years ago
What is the url when it is being called? Formats is usually determined by your url (does it end with xlsx.) axlsx_rails doesn't touch the formats array. You could try passing formats: [:xlsx]
to the render call to force it.
I used to meddle with the formats array, but with Rails 4 there were several side effects so I removed it from the code.
Specifying formats[:xlsx] does fix the problem. Thanks for the prompt help. I greatly appreciate it.
I have to admit, I am confused as to why it is necessary. If I've set up a template and called it through render, as specified in your instructions, doesn't the gem find the template and process it according to the handler? If specifying the xlsx format is a requirement, it would be good to add it to the guidance.
Anyway, thanks again for your help.
If you have ".xlsx" at the end of your url, I am also confused. It shouldn't be necessary. The formats array is composed of the defaults plus whatever comes through the url. If you want to exclude the suffix, you have to force the formats array when the render is called.
Let me know what gems you have for Axlsx, axlsx_rails, and rubyzip. If you have time to create a dummy repo that duplicates the issue it would be a great help. It's hard for me to reproduce these errors without something to work with.
Starting with version 4, Rails started caching the format array between requests, along with several other things that affect the lookup context. I used to be able to tweak those collections and they would be new for the next request. Now any changes are cumulative. I assume it was for speed but it has had side effects. axlsx_rails is doing nothing strange now, and these problems still crop up. Next time I work on axlsx_rails I'll investigate adding some tweaks back.
I will add a note to the troubleshooting section.
I think this is a matter of me not understanding how it worked. The request is the result of a submit, and I give the user the option of rendering the filtered view or exporting to excel, based on which submit button is pushed. So when the request comes through, there is no xlsx extension. I assumed that by calling "render xlsx", it would know I wanted the excel template. The weird thing is, it was working fine, and then stopped for unknown reasons.
No worries. If you ever find what made it work or stop working, return and comment.
I'm having a similar problem and I didn't understood your solution. Where do I need to put formats: [:xlsx] ?
Either url should be set to download.xlsx or while rendering you can set render xlsx: 'download.xlsx'
I had a simple excel report working fine, and today all of a sudden it stopped working. When I attempt to open the file, I get a format not valid error. What I discovered is that the application was rendering the html content of my index.html.erb instead of my index.xlsx.axlsx. I tried renaming the view and explicitly calling the new name:
render xlsx: 'index_export'
I get an error that it cannot find the template.
Missing template passports/index_export, application/index_export with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :axlsx, :jbuilder]}.