我有一个 Rails 应用程序(ruby 2.0.0,Rails 4.2.1)。我想使用acts_as_xlsx gem
.
这是我的控制器:
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
(…)
这是我的模型:
class Vulnerability < ActiveRecord::Base
acts_as_xlsx
end
但是当我点击我的按钮时:
<%= link_to 'Download', url_for(:format=>"xlsx") %>
我有一个错误:
Couldn't find all Vulnerabilities with 'id': (all, {}) (found 0 results, but was looking for 2)
截屏:
任何人都可以帮忙吗?