2

I'm trying to display visitors' names in my rails admin show page. I'm doing it this way:

field :visitors

But I get displayed the following:

Visitor #7 and Visitor #8

I've tried to do something like this with pretty value:

configure :visitors do
  pretty_value do
    bindings[:object].visitors.each do |visitor|
      visitor.full_name
    end
  end
end

But it shows me objects' details:

[#<Visitor id: 7, first_name: "John", last_name: "Smith", created_at: "2016-03-03 10:23:34", updated_at: "2016-03-03 10:23:34", booking_id: 7>, #<Visitor id: 8, first_name: "Bob", last_name: "Smith", created_at: "2016-03-03 10:23:34", updated_at: "2016-03-03 10:23:34", booking_id: 7>]

I simply want to display something like this:

John Smith and Bob Smith

How can I do this?

Daria Voronova
  • 123
  • 2
  • 9
  • This link should be helpful http://stackoverflow.com/questions/11658281/rails-admin-display-name-instead-of-id – Uday kumar das Mar 03 '16 at 11:12
  • @Udaykumardas, thanks for response. Yes, this link is quite good, I've checked it before. But it answers, how to display name for one object. And I have many objects/visitors. – Daria Voronova Mar 03 '16 at 11:14
  • Would changing the `object_label_method` for the `Visitor` class admin config help? (This is assuming you would want a `Visitor` object represented everywhere in your system with their `full_name`) – Paul Fioravanti Mar 12 '16 at 08:17

1 Answers1

2

Well, I've found the solution using map:

bindings[:object].visitors.all.map {|v| v.full_name}.join(', ')
Daria Voronova
  • 123
  • 2
  • 9