John
John

Reputation: 13705

Changing what attribute is displayed in drop down association filter in active admin with Rails 3.1 app

I am using the Active Admin gem in my Rails app, and on one of my models admin page, there is a filter for an association to another model. The drop down menu is displaying #<Model:AxAAAAAA> as opposed to the appropriate attribute.

For instance, if my model were posts, which belonged to users, on the posts admin index page, there would be a filter for users, and in the drop down menu for that filter would be id's such as #<User:abcd12345>. I would like to be able to display something appropriate in the drop down menu for this filter. How can I do this with Active Admin?

UPDATE

As pointed out in the answer by ciastek, this is very similar to this question and in fact, I am also using "company_name" as an attribute instead of "name"

Upvotes: 2

Views: 3121

Answers (2)

John
John

Reputation: 13705

I was able to solve my problem by passing :label_method => :company_name to the resource in the resources.rb file under the 'admin' directory.

Upvotes: 2

ciastek
ciastek

Reputation: 1363

Simmilar to rails activeadmin drop down menu on new and edit forms, answer the same.

  • Use name as a name of field which should represent instance.
  • Define to_s method - value returned by this method will be used as representation.

Upvotes: 1

Related Questions