zolter
zolter

Reputation: 7160

Active admin overwrite index view

For example I have two models:

  1. User - has_many :posts
  2. Post - belongs_to :user

I need column in index view where I can see Posts count of each user:

  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 

My problem is :sortable => "posts.count" does not work, I received exception.

Upvotes: 2

Views: 952

Answers (1)

Grzegorz Łuszczek
Grzegorz Łuszczek

Reputation: 548

Find 4.1.2.4 paragraph on the rails guides. It's about counter_cache. I think that will help you. Just add in ActiveAdmin column :posts_count

Upvotes: 3

Related Questions