I have an Rails app (ruby 2.0.0, Rails 4.2.1). I would like to export data to excel using acts_as_xlsx gem
.
Here is my controller:
class VulnerabilitiesController < ApplicationController
before_action :set_vulnerability, only: [:show, :edit, :update, :destroy]
# GET /vulnerabilities
# GET /vulnerabilities.json
def index
@vulnerabilities = Vulnerability.all
respond_to do | format |
format.html # index.html.erb
format.json { render :json => @vulnerabilities }
format.xlsx {
send_data @vulnerabilities.to_xlsx.to_stream.read, :filename => 'costings.xlsx', :type => "application/vnd.openxmlformates-officedocument.spreadsheetml.sheet"
}
end
(…)
Here is my model:
class Vulnerability < ActiveRecord::Base
acts_as_xlsx
end
But when I click on my button:
<%= link_to 'Download', url_for(:format=>"xlsx") %>
I have an error:
Couldn't find all Vulnerabilities with 'id': (all, {}) (found 0 results, but was looking for 2)
Screenshot:
Can anyone help?