Reputation: 15374
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
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
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
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