[已弃用] Rails 中的简单 AJAX 文件上传
Given other both paid and free uploading tools available, JackUp has been deprecated.
Modify your Gemfile:
gem 'jack_up'and run bundle install from your shell.
Modify your application.js manifest:
//= require jquery
//= require underscore
//= require jack_up
//= require_tree .Rails 4.0+, CoffeeScript, and both jQuery and
Underscore.js included in your application.js manifest.
Create a JackUp.Processor, binding to various events emitted.
…Once the processor is set up, wire up drag-and-drop support:
$('.file-drop').jackUpDragAndDrop(jackUp)
# if you do not want the browser to redirect to the file when droped anywhere else on the page
$(document).bind 'drop dragover', (e) ->
e.preventDefault()If you just want to bind to a standard ``:
$('.standard-attachment').jackUpAjax(jackUp)You can use both at the same time, referencing the same JackUp.Processor, in
order to provide both options to your users.
For instant file uploading:
# Gemfile
gem 'rails'
gem 'paperclip'
gem 'rack-raw-upload'Using the rack-raw-upload gem allows for accessing the file posted to the
controller via params[:file]; this makes it incredibly easy to handle file
uploads.
# app/models/asset.rb
class Asset 'Drop files here' } Drop files here
%input.standard-attachment{ name: 'standard_attachment', accept: 'image/*', type: :file, multiple: :multiple }Anything with a data-placeholder attribute will be hidden when an file is successfully dropped.
If attaching assets to a different model, additionally use:
# app/models/post.rb
class Post 'Drop files here' } Drop files here
%input.standard-attachment{ name: 'standard_attachment', accept: "image/*", type: :file, multiple: :multiple }
= form.submit 'Create Post'…JackUp is copyright 2012-2013 Josh Steiner, Josh Clayton, and thoughtbot, inc., and may be redistributed under the terms specified in the LICENSE file.
暂无开放 Issues,或尚未同步最近议题。