Несколько загружаемых программных пакетов
#app/controllers/adm/galerias_imagem.rb
class Adm::GaleriasImagensController < ApplicationController
layout "adm_layout"
....
def create
@adm_galerias_imagem = Adm::GaleriasImagem.new(adm_galerias_imagem_params)
respond_to do |format|
if @adm_galerias_imagem.save
head :ok
else
head :bad_request
end
end
#app/views/adm/galerias_imagens/new.html.erb
<div id="filelist">Your browser doesn't have Flash, Silverlight or HTML5 support.</div>
<br />
<div id="container">
<a id="pickfiles" href="javascript:;">[Select files]</a>
<a id="uploadfiles" href="javascript:;">[Upload files]</a>
</div>
<%= link_to 'Back', adm_galerias_imagens_path, class: "btn btn-default" %>
<% content_for :js do %>
$(function(){
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
browse_button : 'pickfiles', // you can pass in id...
container: document.getElementById('container'), // ... or DOM Element itself
url : '<%= adm_galerias_imagens_path %>',
multipart: true,
max_file_size : '10mb',
multipart_params: {
"authenticity_token" : "<%= form_authenticity_token %>",
'<%= Rails.application.config.session_options[:key] %>': '<%= request.session_options[:id] %>',
"adm_galerias_imagem[galeria_id]": <%= params[:id] %>
},
flash_swf_url : '/assets/Moxie.swf',
silverlight_xap_url : '/assets/Moxie.xap',
file_data_name:"adm_galerias_imagem[imagem]",
filters : {
max_file_size : '10mb',
mime_types: [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
]
}
});
uploader.bind('Init', function(up, params) {
$('#filelist').html("<div>Current runtime: " + params.runtime + "</div>");
});
uploader.bind('FilesAdded', function(up, files) {
$.each(files, function(i, file) {
$('#filelist').append(
'<div id="' + file.id + '">' +
'File: ' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +'</div>'
);
});
});
uploader.bind('UploadProgress', function(up, file) {
$('#' + file.id + " b").html(file.percent + "%");
});
$('#uploadfiles').click(function(e) {
uploader.start();
e.preventDefault();
});
uploader.init();
});
<% end %>
#app/views/layouts/adm_layout.html.erb
<!--Scripts-->
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<script type="text/javascript">
<%= yield :js %>
</script>