ans*_*809 6 paperclip ruby-on-rails-3 activeadmin
我正在使用paperclip上传多张图片.我也在使用Active Admin.到目前为止,我已经能够上传多个图像并将它们与我的"产品"模型相关联.我还能够在索引页面中显示所有相关图像的"名称".但是,我无法找到如何在产品型号的显示页面中显示 "全部"图像(而不仅仅是名称).请在下面找到代码.
\程序\型号\ product.rb
has_many :images, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
Run Code Online (Sandbox Code Playgroud)
\程序\型号\ image.rb
belongs_to :product
has_attached_file :image, :styles => {
:thumb=> "100x100>",
:small => "300x300>",
:large => "600x600>"
}
Run Code Online (Sandbox Code Playgroud)
\程序\管理\ products.rb
index do
column "Images" do |product|
product.images.map(&:image_file_name).join("<br />").html_safe
end
end
show do |product|
attributes_table do
row "Images" do
ul do
li do
image_tag(product.images.first.image.url(:small))
end
li do
image_tag(product.images.second.image.url(:small))
end
li do
image_tag(product.images.last.image.url(:small))
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
我找到了一些有效的东西,但这是非常糟糕的编程.我目前有3个图像与每个产品相关联,我在我的show块中使用上面的代码.请建议一个更好的方法来做到这一点.
Fiv*_*ell 13
你的意思是你需要显示每个图像而不仅仅是3个图像吗?如果是,请尝试
row "Images" do
ul do
product.images.each do |img|
li do
image_tag(img.image.url(:small))
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5483 次 |
| 最近记录: |