Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Paperclip image in a column Active Admin

I can display an images filename in a column within Active Admin but i cannot seem to get the actual image to show

I have a relationship where

Member
has_many :member_images

MemberImage
belongs_to :member

I can upload an image fine, all associations are in place.

So to show the filename i do

column "Filename" do |f|
  f.member_images.map(&:photo_file_name).join("<br />").html_safe
end

And i have tried this to show the actual image

column "Images" do |m|
  m.member_images do |img|
    image_tag(img.photo.url(:thumb))
  end
end

But i get this error in the view

<ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_MemberImage:0x007f9634a3f760>

Can anyone advise what i am doing wrong please

Thank You

EDIT

Have added a .each so i iterate through each image but now i get this displayed

[#<MemberImage id: 1, member_id: 1, created_at: "2014-02-18 20:28:33", updated_at: "2014-02-18 20:28:33", photo_file_name: "associations.jpg", photo_content_type: "image/jpeg", photo_file_size: 140780, photo_updated_at: "2014-02-18 20:28:33">]
like image 908
Richlewis Avatar asked Mar 21 '23 13:03

Richlewis


2 Answers

Try iterate on you images:

column "Images" do |m|
  m.member_images.each do |img|
    image_tag(img.photo.url(:thumb))
  end
end
like image 94
Philidor Avatar answered Mar 23 '23 02:03

Philidor


Fixed it by add span or other blocks to your image_tag

column "Images" do |m|
  m.member_images.each do |img|
    span do
      image_tag(img.photo.url(:thumb))
    end
  end
end
like image 34
user2684988 Avatar answered Mar 23 '23 02:03

user2684988