我有一个名为Check的模型
class Check < ApplicationRecord
has_many :attendances, :dependent => :destroy
has_many :kids, through: :attendances
accepts_nested_attributes_for :attendances, :allow_destroy => true
belongs_to :groups, optional: true
在Controller的索引中:
respond_to do |format|
format.html
format.xls do
contents = StringIO.new
DataShift::ExcelExporter.new.export(contents, Check.all)
send_data contents.string.force_encoding('binary'), type: 'application/xls'
end
end
我正在使用宝石Datashift来导出具有关联的模型,但它仅导出以下列:
id,名称,created_at,updated_at,group_id,已批准。
另外,我将config / initializers / datashift.rb设置为
# Remove standard Rails cols like :id, created_at, updated_at
# Default is false
#
config.remove_rails = true
# Expand association data into multiple columns
#
config.expand_associations
有人知道为什么它不导出关联,并且即使我在配置文件中将其删除也显示了rails列? 预先感谢!