Remotipart 1.0 Released

31 August 2011

Just 6 weeks after the announcement of v0.4, I'm pleased to announce the release of Remotipart v1.0. With this release, AJAX file uploads in Rails 3.0 and 3.1 (building off the standard jquery-ujs driver) are as easy as humanly conceivable. This was possible thanks to a large push from Adam Kerr.

The two major changes for v1.0 are:

With the release of v1.0, the new officially maintained repo for Remotipart has moved from here to the JangoSteve fork on Github.

There is also now a more robust test suite. Read more about that in the Remotipart docs.

New jQuery iframe-transport

Previously, the process of submitting files via an ad-hoc iframe element and inserting the response back into the page (described here) was done by the form.js. For those who aren't familiar, form.js is an awesome plugin that does a lot of really useful things. However, we weren't really doing it justice by requiring it as a dependency for only one small part of its capabilities.

Also, with the introduction of ajax prefilters and transports in jquery 1.5, there is now a more native way of extending jquery's standard ajax capabilities. Since I finally removed support for jquery 1.4 in the Rails jquery-ujs, remotipart can safely rely on these new transport protocols.

And so for v1.0, we've switched remotipart's to use the jquery iframe-transport.js instead.

Rack middleware

In remotipart v0.4, we added a railtie (for rails 3.0) and a rails engine (for rails 3.1) to automatically add remotipart.js and its dependencies to the JS `:defaults` and asset pipeline, respectively. In v1.0, we've taken it another step further.

There is now a new rack middleware which sits snuggly between the request and your rails app. It automatically communicates with the iframe transport when needed.

$ rake middleware
...
use ActionDispatch::ParamsParser
use Remotipart::Middleware        # < = w00t
use ActionDispatch::Head
...

Because the new middleware does all the translating necessary for ajax file uploads, you no longer need the old `remotipart_response` block in your js.erb response templates.

Additionally, you no longer need to request the JS data-type (you could request other data-types before, but anything other than JS or HTML could be a bit buggy in IE). Remotipart is now compatible with all data-types.

AJAX file uploads are easier than ever

So what does all this mean? It means that AJAX files uploads in Rails 3 are now so incredibly easy, I have no problem dubbing this v1.0.

Let's say you have a Rails 3 app with a remote form. Everything goes great, but then you add a file input to the form. Suddenly, the form won't submit via ajax anymore. This is by design, since a simple ajax request is incapable of uploading files.

Just install Remotipart 1.0.

For rails 3.0 apps, run: ```bash bundle exec rails g remotipart:install ```

For rails 3.1 apps, require remotipart.js in your `app/assets/application.js`: ```js //= require jquery.remotipart ```

Done! The form will now upload the file via ajax no problem.

About the author:

Steve Schwartz // Owner of Alfa Jango, CTO of Genomenon, co-founder of Carcode (acquired by Edmunds.com in 2014), engineer, developer, open-source enthusiast, guitarist, and racecar driverist.



Comments are loading...


We're Hiring!