Reputation: 133
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?
Upvotes: 2
Views: 565
Reputation: 133
Well, I've found the solution using map:
bindings[:object].visitors.all.map {|v| v.full_name}.join(', ')
Upvotes: 2