Заголовки не отображаются с помощью to_xls - PullRequest
0 голосов
/ 16 сентября 2011

Я использую гем to_xls , и это здорово - генерировать файлы xls из activerecords. Но по какой-то причине я не могу найти заголовки.

enter image description here

Вот контроллер:

  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]
    )
  }

1 Ответ

0 голосов
/ 14 марта 2012
Плагин

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"]
    )
}
...