我可以在活动管理员的列中显示图像文件名,但我似乎无法显示实际图像
我有一段关系
Member
has_many :member_images
MemberImage
belongs_to :member
我可以上传图像很好,所有关联都到位。
所以为了显示文件名,我做了
column "Filename" do |f|
f.member_images.map(&:photo_file_name).join("<br />").html_safe
end
我已经尝试过这个来显示实际图像
column "Images" do |m|
m.member_images do |img|
image_tag(img.photo.url(:thumb))
end
end
但是我在视图中收到此错误
<ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_MemberImage:0x007f9634a3f760>
任何人都可以告诉我我做错了什么吗
谢谢
编辑
添加了一个 .each,所以我遍历每个图像,但现在我显示它
[#<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">]
尝试迭代您的图像:
column "Images" do |m|
m.member_images.each do |img|
image_tag(img.photo.url(:thumb))
end
end
通过在image_tag中添加跨度或其他块来修复它
column "Images" do |m|
m.member_images.each do |img|
span do
image_tag(img.photo.url(:thumb))
end
end
end
在查看了其他一些具有类似问题的帖子后,我可以像这样在我的列中显示图像
column "Images" do |m|
ul do
m.member_images.each do |img|
li do
image_tag(img.photo.url(:thumb))
end
end
end
end
虽然我不太确定为什么会这样