Dung Pham
Dung Pham

Reputation: 95

Display multiple images in rails_admin

I am using rails_admin with Rails 5. I have a model Hotel with an association images (has_many). Currently I use the default config of rails_admin, and under Hotel show page, the images of a hotel are displayed in this format:

Image #5381, Image #5382, Image #5383, Image #5384, Image #5385,...

How can I display these images as a gallery given that each image has a thumbnail_url attribute? I means which config I could put in this block to change the display:

show do
  field :images do
    # Display as a gallery
  end
end

Thanks for your time!

Upvotes: 0

Views: 651

Answers (1)

gwcodes
gwcodes

Reputation: 5690

Rendering a custom partial is probably the best approach here. Something like:

field :images do
  render do
    bindings[:view].render partial: 'image_preview', locals: {object: self}
  end
end

Then create the partial in app/views/rails_admin/main/_image_preview.html.*, and you're free to control what appears.

Upvotes: 1

Related Questions