2013-05-18 17 views
2

我使用的是active_admin和carrierwave寶石。有兩個簡單的模型:active_admin並將多個圖像添加到圖庫

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 

現在我的畫廊active_admin形式如下:

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

現在我可以上傳一個文件,點擊「添加新形象」,並上傳另一個。而不是它,我想單擊「添加新圖像」,選擇多個文件並一次全部上傳。任何想法我怎麼能實現它?

+0

你有沒有嘗試更新插件'carrierwave'使用javascrips如jQuery? – hendrathings

+0

+1在這個問題上。你有沒有想過呢? – elsurudo

回答

1

對於有多個圖像上傳圖庫的形式,你可以試試這個

管理/ galleries.rb

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

在模型/ gallery.rb:

attr_accessible :images_attributes 

在model/gallery.rb(關係後添加):

accepts_nested_attributes_for :images, :allow_destroy => true