Active Admin: Propper relation names in filters
Imagine the following situation:
app/models/post.rb:
class Post < ActiveRecord::Base
belongs_to :user
end
app/admin/post.rb:
ActiveAdmin.register Post do
filter :user
end
You will see a dropdown for user in filter sidebar with values like #User:0x007f89551ea448
If you want to set a propper name for associated model
just define a method "name" for it:
app/admin/user.rb:
class User < ActiveRecord::Base
def name
self.email
end
end
And you'll see a propper email in a dropdown
Written by Seva Rybakov
Related protips
1 Response
I believe ActiveAdmin uses display_name
as the method behind the scenes, but will go through a list of possible methods to call on the object in order, such as: name
, title
, display_name
, & to_s
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#