本文介绍了active_admin并将多个图像添加到图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用active_admin和carrierwave宝石。有两个简单的模型:

I'm using active_admin and carrierwave gems. Have two simple models:

class Image < ActiveRecord::Base
  attr_accessible :gallery_id, :file
  belongs_to :gallery

  mount_uploader :file, FileUploader
end

class Gallery < ActiveRecord::Base

  attr_accessible :description, :title, :file, :images_attributes
  has_many :images
  accepts_nested_attributes_for :images, allow_destroy: true

  mount_uploader :file, FileUploader
end

现在,我用于Gallery的active_admin表单如下:

Now my active_admin form for Gallery looks like this:

form do |f|
  f.inputs "Gallery" do
    f.input :title
  end
  f.has_many :images do |ff|
    ff.input :file
  end
  f.actions
end

现在,我可以上传一个文件,单击添加新图像并上传另一个文件。取而代之的是,我想单击添加新图像,选择多个文件,然后一次全部上传。知道如何实现吗?

Now I can upload one file, click "Add New Image" and upload another one. Instead of it, I'd like to click "Add new Image", select multiple files and upload them all at once. Any idea how can I implement it?

推荐答案

对于具有多个图片上传功能的Gallery表格,您可以尝试

For a Gallery form with multiple image uploads you can try this

admin / galleries.rb

  form do |f|
    f.inputs "Gallery" do 
      f.input :name
    end
    f.has_many :images do |ff|
      ff.input :file
    end
  end

在model / gallery.rb中:

attr_accessible :images_attributes

在model / gallery.rb中(关系添加):

accepts_nested_attributes_for :images, :allow_destroy => true

这篇关于active_admin并将多个图像添加到图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 12:05