我试图为我的搜索结果添加 csv,但它会抛出错误,告知未经允许的参数。我应该在 csv 链接中传递哪些参数?这样 csv 将只下载搜索结果。
报告控制器
def revenue_search
@bookings = Booking.complete.order("created_at DESC")
date = "1-#{params['date']['month']}-#{params['date']['year']}"
date = Date.parse(date)
@bookings = @bookings.where(created_at: date.beginning_of_month..date.end_of_month)
@per_page = params[:per_page] || Booking.per_page || 20
@bookings = @bookings.paginate( :per_page => @per_page, :page => params[:page])
if params[:currency].present?
@bookings = @bookings.where(currency: params[:currency])
end
respond_to do |format|
format.html
format.csv { send_data @bookings.revenue_csv }
end
end
Run Code Online (Sandbox Code Playgroud)
模型
def self.revenue_csv
attributes = %w{ total value deposit balance }
CSV.generate(headers: true) do |csv|
csv << attributes
all.each do |booking|
csv << …Run Code Online (Sandbox Code Playgroud) 我有一个布尔值的矩阵:
require 'matrix'
m1 = Matrix[[0,1,1,1],[0,0,1,1],[1,1,1,1],[0,0,0,0]]
Run Code Online (Sandbox Code Playgroud)
我想找到最大数量为1s 的行.谁能帮我?