RailsAdmin and Devise - displaying username in tables
I'm using the rails_admin gem and Devise in my app where I have a Post model.
Each Post belongs to a User. Users have a :username
attribute
I'm 开发者_StackOverflow中文版trying to configure rails_admin to display the user's username in the list view but instead it's displaying "User #1", "User #2" etc
Here's my rails_admin code:
config.model Post do
label "Blog"
list do
field :id
field :title
field :published
field :user_id
field :created_at
end
end
I'd really like rails_admin to display the :username for each user. Is there an easy way to do this?
Use object_label
:
config.model Post do
label "Blog"
object_label do
"#{bindings[:object].user.username}"
end
list do
field :id
...
end
end
精彩评论