Seal Seal - 1 year ago 197
Ruby Question

Rails ActionController unknown format

I am trying to render a

file. But I keep getting a
. I have done the right setup, maybe im missing something?

Rails 4.2 app

gem 'axlsx'
gem "axlsx_rails"
gem 'zip-zip'


Mime::Type.register "application/xlsx", :xlsx


respond_to do |format|
format.xlsx { render xlsx: "create", template: "api/reports/create" }


wb = xlsx_package.workbook
wb.add_worksheet(name: "Reports") do |sheet|
sheet.add_row [@report_name]

Answer Source

The error you are getting doesn't mean that rails didn't find the the xlsx format: it means that it compared the list of formats you're providing (i.e. just xlsx) and compared it to the set of formats it thinks the browser is willing to accept and didn't find any overlap.

If as it appears there is only one format you want to render then you don't need to use respond_to at all - just replace the whole thing with

render xlsx: "create", template: "api/reports/create"

Rails derives what it thinks are acceptable formats from the extension on the url and the Accept header. Format negotiation is generally simply done via the extension than the Accept header - linking (or posting) to /some/path.xlsx should set the format to xlsx. You can do this by including format: 'xlsx' in the options you pass to path helpers or as part of a hash of routing options.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download