开发者

RailsAdmin and Devise - displaying username in tables

开发者 https://www.devze.com 2023-03-04 05:08 出处:网络
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 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
0

精彩评论

暂无评论...
验证码 换一张
取 消