Richlewis
Richlewis

Reputation: 15374

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">]

Upvotes: 4

Views: 4046

Answers (3)

user2684988
user2684988

Reputation: 27

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

Upvotes: 2

Richlewis
Richlewis

Reputation: 15374

After looking at some other posts with similar issues i can display the image within my column like so

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

Though I'm not quite sure why this works

Upvotes: 0

Roman Kiselenko
Roman Kiselenko

Reputation: 44360

Try iterate on you images:

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

Upvotes: 5

Related Questions