I wont to upload multiple file in rails_admin
my model config
class EducationMaster < ActiveRecord::Base
attr_accessible :address, :city, :country, :name, :state, :zip,:photos
has_many :photos, :dependent => :destroy
end
class Photo < ActiveRecord::Base
belongs_to :education_master
attr_accessible :education_master_id, :image
mount_uploader :image, ImageUploader
end
please help me to upload multiple file using rails admin my rails version 3.2.13 ruby 1.9.3
I wrote a tutorial about multiple file upload with RailsAdmin and HTML5, maybe you will find it helpful: http://blog.powpark.com/2013/10/16/multiple-file-upload-with-html5-and-rails-admin/
Basically you need to create a custom RailsAdmin action, using:
rails plugin new rails_admin_multiple_upload -m https://gist.github.com/bbenezech/1621146/raw/5268788e715397bf476c83d76d335f152095e659/rails_admin_action_creator --skip-gemfile --skip-bundle -T -O -S -J --full
Then amend the engine file:
class MultipleUpload < Base
RailsAdmin::Config::Actions.register(self)
register_instance_option :member do
true
end
register_instance_option :link_icon do
'icon-upload'
end
register_instance_option :http_methods do
[:get, :post]
end
register_instance_option :controller do
Proc.new do
@response = {}
if request.post?
@album = Album.find_by_id(params[:album_id])
@album.update_attribute(:photos_attributes, params[:album][:photos_attributes])
end
render :action => @action.template_name
end
end
end
Amend the view file:
= simple_form_for(rails_admin.multiple_upload_url(@abstract_model.to_param), html: { multipart: true }) do |f|
= f.input :album_id, :as => :hidden, :input_html => { :name => "album_id", :value => @object.id }
= file_field_tag('album_photos_file', multiple: true, name: "album[photos_attributes][][file]")
= f.submit :submit, value: 'Upload', name: 'Upload', :class => 'btn btn-primary'
I hope this is helpful.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.