-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export Invalid .xlsx file in Api only mode #107
Comments
Thanks! I'll take a look. I don't remember the differences off the top of my head. |
@NickBeukema I've spent some time looking at this and found the axlsx_rails template handler is not being called by the api even though the renderer is. I'll have to spend more time when I can digging into Rails itself to find the error. Have you tried this with rails 5.1 or earlier? |
Also I notice the api is rails 5.1.4 and the regular is 5.2.1. Did you just create a generic api? |
Same issue here. |
For now I just made my From
to
|
I’ve spent a few hours in this. Hopefully I will get some more time this week. It is deep in the inheritance tree. |
@NickBeukema @fresh2nd I would do one of two things:
If either of you do so, consider adding a pull request for the README. Or drop it here. I will do it at some point. |
Based on this issue: rails/rails#27211 class TestController < ActionController::API
include ActionView::Rendering
def show
respond_to do |format|
format.xlsx
end
end
private
def render_to_body(options)
_render_to_body_with_renderer(options) || super
end
end And now you can export correct xlsx file, but still need better solution here. |
@DonaldChiang Did you ever find a better solution? What kind of solution were you imagining? |
Closing after adding this to the readme. |
There is another possibility. If you only have a Rails API, you really don't need to organize the code in templates. Instead consider using service classes to organize your code. Or something similar. |
I have created a base repo:
https://github.com/NickBeukema/axlsx_rails_testing
For both regular and api only mode, for both have done the following
Lead
model with propertiesName
andOccupation
LeadsController
withindex
method, addresources :leads
to routes fileviews/leads/index.xlsx.axlsx
file for rendering the.xlsx
fileI visit the url and the api only version exports the file as 1 byte and cannot be opened, while the non api only version exports the excel file normally.
To reproduce the two repos, do the following:
rails db:migrate db:seed
rails s
localhost:3000/leads.xlsx
I've also added a
json
responder to assure that the data is there and therespond_to
function is working, so you can visitlocalhost:3000/leads.json
to see the json data.Do you know what dependencies I'm missing in the api only version? I've already included
ActionController::MimeResponds
to allow forrespond_to
usage. Any help would be great!The text was updated successfully, but these errors were encountered: