我正在使用gem to_xls,从activerecords生成xls文件非常棒。但由于某些原因,我无法显示标题。
这是控制器:
format.xls {
send_data @tickets.to_xls(
:columns => [:created_at, :title, {:category => :title}, {:group => :name}, {:location => :name}, :starts, :target, {:requestor => :full_name}, :percent_complete, :recurring, :cost, :spent, :task_level],
:headers => [:created, :name, :category, :group, :location, :start_date, :target_date, :requestor, :percent_complete, :recurring, :cost, :spent, :task_level]
)
}
答案 0 :(得分:0)
to_xls插件不显示带有关联模型的标头,因为它无法理解属性名称。
您可以尝试为标题而不是属性提供字符串:
format.xls {
send_data @tickets.to_xls(
:columns => [:created_at, :title, {:category => :title}, {:group => :name}, {:location => :name}, :starts, :target, {:requestor => :full_name}, :percent_complete, :recurring, :cost, :spent, :task_level],
:headers => ["created", "name", "category", "group", "location", "start_date", "target_date", "requestor", "percent_complete", "recurring", "cost", "spent", "task_level"]
)
}