ActiveAdmin Papperclip在索引和显示中显示多个图像

时间:2015-05-29 00:52:49

标签: ruby-on-rails-4 paperclip activeadmin nested-forms

您只是在索引页面和显示页面上显示多个图像的快速问题。我的图像存储在product_images表中,其中product_id作为外键。

现在就在这个圈子里。我尝试使用类似的代码无济于事。

 row "Images" do
        ul do
          product.images.each do |img|
            li do
              image_tag(img.image.url(:small))
            end
          end
        end
      end
ActiveAdmin.register Product do

  # See permitted parameters documentation:
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  #
   permit_params :id, :product_name, :product_description, :product_type_id, :product_category_id, :product_colour_id, :product_size_id,
                             product_images_attributes: [:id, :product_id, :product_image, :_destroy ]
  #
  # or
  #
  # permit_params do
  #   permitted = [:permitted, :attributes]
  #   permitted << :other if resource.something?
  #   permitted
  # end

  index do
          column :id
          column :product_name
          column :product_description

    actions
  end

   form(:html => {:multipart => true}) do |f|
     f.inputs "Product Details" do
       f.input :id
       f.input :product_name
       f.input :product_description

       f.inputs "Product images" do
         f.has_many :product_images do |p|
           p.input :product_image, :as => :file, :label => "Image",:hint => image_tag(p.object.product_image.url(:thumb))
           p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image'
         end
       end
        f.actions
   end
end


  show title: :product_name do

    attributes_table do
      # other rows
      row :id
      row :product_name
      row :product_description

      end
  end

end

解 更多的游戏,我修复了它

index do
      column :id
      column :product_name
      column :product_description
      column "Images" do |m|
        m.product_images.each do |img|
          span do
            image_tag(img.product_image.url(:thumb))
          end
        end
      end
      actions
 end

 show title: :product_name do

attributes_table do
  # other rows
  row :id
  row :product_name
  row :product_description
      row "Images" do |m|
        m.product_images.each do |img|
          span do
           image_tag(img.product_image.url(:thumb))
         end
        end
       end
      end
  end

1 个答案:

答案 0 :(得分:0)

index do
      column :id
      column :product_name
      column :product_description
      column "Images" do |m|
        m.product_images.each do |img|
          span do
            image_tag(img.product_image.url(:thumb))
          end
        end
      end
      actions
 end

 show title: :product_name do

attributes_table do
  # other rows
  row :id
  row :product_name
  row :product_description
      row "Images" do |m|
        m.product_images.each do |img|
          span do
           image_tag(img.product_image.url(:thumb))
         end
        end
       end
      end
  end