= Remotipart Remotipart is a Ruby on Rails gem enabling AJAX file uploads with jQuery in Rails 3.0 and Rails 3.1 remote forms. This gem augments the native Rails jQuery remote form functionality enabling asynchronous file uploads with little to no modification to your application. * {Homepage and Demos}[http://www.alfajango.com/blog/remotipart-rails-gem/] * {How AJAX File Uploads Work}[http://www.alfajango.com/blog/ajax-file-uploads-with-the-iframe-method/] == Dependencies * {Rails 3}[http://github.com/rails/rails] * {The jquery-rails gem}[http://rubygems.org/gems/jquery-rails], which really just installs {jQuery}[http://jquery.com] and the {Rails jQuery driver (jquery-ujs)}[https://github.com/rails/jquery-ujs] == Installation Your app should be using jquery-rails gem v1.0.12 or above (except jquery-rails v2.0.3 and v2.1.0; there was a {bug in jquery-rails}[https://github.com/rails/jquery-ujs/issues/271] which causes remotiarpt to not work for those versions). If you're using an old version of the jquery-rails gem, make sure you have a supported jquery-ujs (rails.js or jquery_ujs.js) version from {VERSION_COMPATIBILITY}[https://github.com/JangoSteve/remotipart/blob/master/VERSION_COMPATIBILITY.rdoc]. [1.] Install the Remotipart gem * Add this line to your GEMFILE (use the appropriate version from the compatibilty chart if needed) gem 'remotipart', '~> 1.0' * And run bundle install === Rails 3.1 [2.] The necessary js files will automatically be added to the asset pipeline, so add the following to app/assets/javascripts/application.js (right after //= require jquery_ujs): //= require jquery.remotipart === Rails 3.0 [2.] Run the Remotipart install generator to add jquery.iframe-transport.js and jquery.remotipart.js to public/javascripts/ rails g remotipart:install [3.] The necessary js files will be added to your app's javascript :defaults, so make sure the following is in your application layout: <%= javascript_include_tag :defaults %> == Usage * For multipart / forms with file inputs, set your form_for to remote as you would for a normal ajax form: :remote => true * When Javascript is enabled in the user's browser, the form, including the file, will be submitted asynchronously to your controller with: :format == 'js' * If you need to determine if a particular request was made via a remotipart-enabled form... * from your Rails controller or view: if remotipart_submitted? * from your javascript: $(form).bind("ajax:success", function(){ if ( $(this).data('remotipartSubmitted') ) }); === Example sample_layout.html.erb <%= form_for @sample, :html => { :multipart => true }, :remote => true do |f| %>