Topic: accessing model associations in the rails-admin list?

Hi everyone,

I am trying out the rails-admin plugin (https://github.com/sferik/rails_admin), and I am trying to create a field for the number of posts a user has created...

I tried doing:

RailsAdmin.config do |config|
  config.model User do
    
    list do
      field :posts do
        formatted_value do
           value.count
         end
      end
    end
  end
end

but I get:

ZeroDivisionError in Rails_admin/main#list

..  yet, if I make a method in the model like:

class User < AR:Base

  def my_posts
    posts
  end

end

and then change the config to reference my_posts, then it works fine.... Does anyone know a way around this?

-patrick

Last edited by patrick99e99 (2011-06-15 19:19:35)