安装 gem 后,acts_as_xlsx我看不到如何在活动记录中返回相关字段。
class Ticket < ActiveRecord::Base
  acts_as_xlsx  :columns => [:customer_name ]
  attr_accessible :customer_id, :account_id, :first_weight, :ticket_no, :second_weight, :net_weight, :product_id, :vehicle_id, :customer_name, :vehicle_reg, :product_details, :weight
  belongs_to :customer
  belongs_to :vehicle
  belongs_to :product
  belongs_to :account
当通过tickets.xlsr 生成文件时,我得到cutomer_id 的结果,即30 不是客户名称我如何返回名称?
控制器
def report
    @q = @gaurd.ticket.where("net_weight > 0").paginate(:page => params[:page], :per_page => 10).search(params[:q])
    @ticket = @q.result(distinct: true)
    respond_to do |format|
      format.html
      format.xlsx {
      xlsx_package = @ticket.to_xlsx
      begin 
        temp = Tempfile.new("report.xlsx") 
        xlsx_package.serialize temp.path
        send_data xlsx_package.to_stream.read, :filename => 'tickets.xlsx', :type=> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        ensure
        temp.close 
        temp.unlink
      end
      }
    end
  end
我花了一天的大部分时间来尝试,但除了诸如 customer_id 之类的字段数据之外,无法下载相关的数据ticket.customer.name