multiupload-uploadify
Multiupload-uploadify is a gem for multiupload using the uploadify plugin
###Getting started
To use add this to your Gemfile
gem "multiupload-uploadify"
Run the bundle command to install it.
Now you need run the generate command
rails generate multiupload_uploadify
Add this in your application.js
//= require jquery.uploadify-3.1
//= provide dependencies
and this to your application.css
*= require uploadify
To use the muptiupload gem you can use the helper method in your view
<%= multiupload_field :url => new_photo_path %>
and add this in your layout file
<%= content_for :scripts if content_for? :scripts %>
and in your controller you can get the files through the Filedata param
Photo.create(:picture => params[:Filedata])
if you want to know the id of the model you need do this
in your controller
photo = Photo.create(:picture => params[:Filedata])
render :text => photo.id
and pass a javascript function responsible for handling the return of the request
<%= multiupload_field :url => new_photo_path, :options => { :onUploadSuccess => 'myFunction' %>
<script type="text/javascript">
function myFunction(file, data, response){
alert(data);
}
</script>
any other parameter of the plugin you can pass using
<%= multiupload_field :url => new_photo_path, :options => { :buttonText => '"Upload Photos"' %>
devise + multiupload-uploadify
if you use the devise gem you need pass the parameters of your session for authentication you can do it like this:
<%= multiupload_field :url => new_photo_path, :parameters => {Rails.application.config.session_options[:key] => "'#{cookies[Rails.application.config.session_options[:key]]}'" } %>