Giter Club home page Giter Club logo

remotipart's Introduction

Remotipart

Remotipart is a Ruby on Rails gem enabling remote multipart forms (AJAX style file uploads) with jQuery. This gem augments the native Rails jQuery remote form function enabling asynchronous file uploads with little to no modification to your application.

Dependencies

Installation

  1. Install the Remotipart gem

gem install remotipart
  1. Run the Remotipart generator to add jquery.remotipart.js to public/javascripts/

rails g remotipart
  1. Add the Javascript files for jQuery, the Rails jQuery driver, jQuery Form plugin, and Remotipart to your template, making sure to include jquery.remotipart.js after the jQuery and the Rails jQuery driver

<%= javascript_include_tag 'jquery-1.4.2.min', 'rails', 'jquery.form', 'jquery.remotipart' %>

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’

  • In the JS response template for your controller action, wrap all of your response code in one remotipart_response block: <%= remotipart_response do %> All Javascript response code goes here <% end %>

Example

sample_layout.html.erb

<%= form_for @sample, :html => { :multipart => true }, :remote => true do |f| %>
  <div class="field">
    <%= f.label :file %>
    <%= f.file_field :file %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

sample_controller.rb

def create
  respond_to do |format|
    if @sample.save
      format.js
    end
  end
end

create.js.erb

<%= remotipart_response do %>
  //Display a Javascript alert
  alert('success!');
<% end %>

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Greg Leppert. See LICENSE for details.

remotipart's People

Contributors

leppert avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.