1

假设我有一个 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列显示具有行跨度的可排序表?

预期的输出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>
4

1 回答 1

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
于 2013-03-11T12:09:37.883 回答