2012-03-28 82 views
2

比如我有兩個型號:主動管理覆蓋索引視圖

  1. 用戶 - 的has_many:帖子
  2. 後 - belongs_to的:用戶

我需要在索引視圖欄在那裏我可以看到每個用戶的帖子數:

index do 
    column :id 
    column :name 
    column :created_at 
    column "Posts count", :sortable => "posts.count" do |user| 
     user.posts.count.to_s 
    end 
    default_actions 
    end 

我的問題是:sortable =>「posts.count」不起作用,我收到異常。

+0

你試過了:sortable => false? – 2012-03-28 12:07:00

+0

但是我需要對這一列進行排序,我應該怎麼做? – zolter 2012-03-28 12:08:27

+1

它會告訴你與每個用戶相關的帖子數 – 2012-03-28 12:09:08

回答

3

查找關於the rails guides的4.1.2.4段落。這是關於counter_cache。我認爲這會幫助你。只需在ActiveAdmin中添加column :posts_count