如何在ActiveAdmin的仪表板中自定义具有自定义查询的可排序表

时间:2013-03-02 11:05:41

标签: ruby-on-rails activeadmin

假设我有一个ActiveRecord查询:

User.select('name', 'created_at').all
=> [#<User created_at: "2012-08-06 13:27:40", name: "Alice">, #<User created_at: "2012-08-06 15:41:33", name: "Bill">]

如何按created_at列显示包含rowspan的可排序表格?

预期输出html:

   <table>
      <tr>
          <th>created_at</th>
          <td>name</td>
      </tr>
      <tr>
          <td>2012-08-06</td>
          <td>Alice</td>
      </tr>
      <tr>
          <td>2012-08-06</td>
          <td>Bill</td>
      </tr>   
  </table>

1 个答案:

答案 0 :(得分:0)

您应该阅读文档:http://activeadmin.info/docs/3-index-pages/index-as-table.html

假设您使用的是上一个版本(0.5.1):

index do
  column "created_at", :sortable => :created_at do |user|
    user.created_at.strftime('%Y-%m-%d') # if the format is different that expected
  end
  column "name", :sortable => :name do |user|
    user.name
  end
end