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

ActiveAdmin Papperclip Show multiple images in Index and show

您好,关于在索引页和显示页上显示多个图像的快速问题。我的图像存储在 product_images table 中,外键为 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

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