Giter Site home page Giter Site logo

jangosteve / remotipart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leppert/remotipart

1.0K 29.0 215.0 220 KB

Rails jQuery file uploads via standard Rails "remote: true" forms.

Home Page: http://os.alfajango.com/remotipart

License: Other

Ruby 87.80% HTML 5.88% JavaScript 4.14% CSS 2.18%

remotipart's Introduction

Remotipart: Rails jQuery File Uploads

<img src=“https://badge.fury.io/rb/remotipart.svg” alt=“Gem Version” /> <img src=“https://travis-ci.com/JangoSteve/remotipart.svg?branch=master” alt=“Build Status” /> <img src=“https://codeclimate.com/github/JangoSteve/remotipart/badges/gpa.svg” />

Remotipart is a Ruby on Rails gem enabling AJAX file uploads with jQuery in Rails 3 and Rails 4 remote forms. This gem augments the native Rails jQuery remote form functionality enabling asynchronous file uploads with little to no modification to your application.

Dependencies

The jquery-rails gem is included in Rails 3 and Rails 4 by default, and installs {jQuery}[http://jquery.com] and the {Rails jQuery UJS driver (jquery-ujs)}[https://github.com/rails/jquery-ujs]

Installation

Your app should be using jquery-rails gem v2.3.0 or above.

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.

1.

Install the Remotipart gem

  • Add this line to your GEMFILE (use the appropriate version from the compatibilty chart if needed)

gem 'remotipart', '~> 1.2'
  • And run

bundle install

Rails 3.1 and Rails 4

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') )
      });
  • If you want to be notified when the upload is complete (which can be either success or error)

    • from your javascript:

      $(form).on("ajax:remotipartComplete", function(e, data){
        console.log(e, data)
      });

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

// Display a Javascript alert
alert('success!');
<% if remotipart_submitted? %>
  alert('submitted via remotipart')
<% else %>
  alert('submitted via native jquery-ujs')
<% end %>

The content type requested from the application can be overridden via the data-type HTML5 attribute:

sample_layout2.html.erb

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

In this case, the application should serve HTML using a create.html.erb template instead of JavaScript.

Note on Patches/Pull Requests

If you have a general improvement, optimization, or refactoring, please {read this first}[https://github.com/formasfunction/remotipart/wiki/Refactoring-and-Improving-Remotipart].

  • 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.

Tests

Because of the nature of AJAX file uploads and certain browser restrictions, we could not simply create unit tests (using qunit or jasmine) to test the file upload functionality of remotipart (since the browsers running those test suites won’t allow us to set the target of a file upload input using javascript). So, instead we created a demo Rails app using remotipart with all remotipart functionality tested using RSpec and Capybara.

To run tests:

Clone the remotipart branch of the demo app

git clone -b remotipart git://github.com/JangoSteve/Rails-jQuery-Demo.git

Install the dependencies

bundle install

Run the tests

bundle exec rspec spec/

If you need to test your own changes to remotipart, just update the Gemfile with your own fork/branch of remotipart:

gem 'remotipart', :git => 'git://github.com/MY_FORK/remotipart.git', :branch => 'MY_BRANCH'

Special Thanks

Thank you to Greg Leppert for writing the original version of this gem and providing inspiration for the gem in its current incarnation.

Thank you to Adam Kerr for helping move over to the simpler jQuery 1.6-compatible iframe-transport.js and for helping write the rack middleware, making remotipart even easier to use in Rails.

Copyright © 2013 Steve Schwartz, Greg Leppert. See LICENSE for details.

remotipart's People

Contributors

ai avatar ajrkerr avatar amatsuda avatar amleaver avatar arr-dev avatar codegoalie avatar dandv avatar danring avatar edouard-chin avatar esbanarango avatar hermesdt avatar jangosteve avatar kdmny avatar koic avatar leppert avatar mattolson avatar mshibuya avatar mvelikov avatar ordinaryzelig avatar rcook avatar shwoodard avatar sktocha avatar tallama avatar vivid avatar vivrass avatar westonganger avatar yasirs avatar znz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

remotipart's Issues

Remotipart sending [object Object] to server.

I have a form for uploading a file.

<%= form_for @import, remote: true do |f| %>
  <fieldset>
    <%= f.label :file, "Attach a CSV file" %>
    <%= f.file_field :file %>
  </fieldset>
  <%= f.submit :upload %>

<% end -%>

Unfortunately, when I submit the form with a file attached, it doesn't seem to arrive at my controller action correctly. The params hash has stringified JS objects as keys.

Started POST "/file_imports" for 127.0.0.1 at 2012-11-06 01:00:49 +0000
Processing by FileImportsController#create as JS
  Parameters: {"object Object"=>{","=>{"object Object"=>{","=>{"object Object"=>nil}}}}}`

Looking into the Remotipart source, I can't seem to understand what it is supposed to do. For example, in vendor/assets/javascripts/jquery.remotipart.js, Line 22 has the following:

settings.data = form.serializeArray();

A little further down, the settings are sent to the server via $.rails.ajax(settings).

The $.fn.serializeArray() method returns an array of JS objects. If we assign them to the data attribute of a call to jQuery.ajax(), that would account for the serialized object parameters I'm seeing on the server. We need to pass an object as the data attribute, not an array of objects?

Am I doing something wrong or how exactly is this meant to work?

Not compatible with Rails 3.2.3

I tried to use remotipart(1.0.2) with rails version 3.2.3. I felt these two gems are not compatible with each other. The helper method remotipart_submitted? was returning false. So I downgraded rails to 3.1.6 and remotipart to 1.0, now, it seems they are working together.

Use the form to submit file and other data

Is the a way to upload a file and other form data in one request without hacking around js and the server code? If I add data and files to .ajax() call - it merges data and misses some file uploads data on submission.

Rails ujs callback not work

After I apply the remotipart, the form submit works fine with ajax. But the ujs callback that provided from Rails seems not working. So how can I make it work again? Thanks.

BTW, I am using JQuery 1.7.1. .on() for binding the ajax:success. And I put alert there which has nothing popup. Not sure if it's the case of the JQuery version.

render_overrides broken when wicked_pdf present

If you add

gem 'wicked_pdf'

to the Gemfile in https://github.com/JangoSteve/Rails-jQuery-Demo/tree/remotipart the render method created in the RenderOverrides module include to ActionController::Base never gets run during regular request processing, and therefore renders remotipart's response handling on the client side nonfunctional.

wicked_pdf is monkeying around with method chaining of render inside one of their ActionController::Base-included modules, perhaps that has something to do with it:

  def self.included(base)
    base.class_eval do
      alias_method_chain :render, :wicked_pdf
      alias_method_chain :render_to_string, :wicked_pdf
      after_filter :clean_temp_files
    end
  end

Smells to me like one or both projects are doing something inadvisable, but I really don't have the depth of expertise to make that assessment.

See mileszs/wicked_pdf#111 for more details.

Rails 3.2.11 / jquery-rails 2.2.0 (jquery 1.9.0) / Probably another compatibility problem

Except the live / on compatibility problem mentioned previously it seems there is another compatibility problem :

Everything works fine with Rails 3.2.11 / jquery-rails 2.1.4 (jquery 1.8.3) and I got th following :

Processing by Adminapp::AlbumsController#update_avatar as JS
  Parameters: {"album"=>{"avatar_attributes"=>{"asset"=>#<ActionDispatch::Http::UploadedFile:0x9e65754 @original_filename="diaporama-AAK.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"album[avatar_attributes][asset]\"; filename=\"diaporama-AAK.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20130121-28398-nvf7tn>>, "id"=>"5"}, "title"=>"Singapore", "description"=>"Photos of new year"}, 
"utf8"=>"✓", authenticity_token"=>"8wUgkSz6rwNohY2VMncHYp8a9uI8Av5777DvO16QBXg=", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "id"=>"7", "locale"=>"en"}

But with jquery-rails 2.2.0 (jquery 1.9.0) I got this :

Processing by Adminapp::AlbumsController#update_avatar as JS
  Parameters: {"album"=>{"avatar_attributes"=>{"asset"=>"diaporama-AAG.jpg", "id"=>"5"}, "title"=>"Singapore", "description"=>"Photos of new year"}, "utf8"=>"✓", "authenticity_token"=>"8wUgkSz6rwNohY2VMncHYp8a9uI8Av5777DvO16QBXg=", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "id"=>"7", "locale"=>"en"}

It's like remotipart do not take the Asset object anymore but only the name of the file.
I tried debug it but my Javascript knowledge is very poor.

Fred.

$.ajax or $.post

Hi Steve,

First off, awesome gem from you and leppert. Thanks! Question, can I use $.ajax or $.post to submit the file or file_field? If so, how can I do that?

Remotipart POST method shows canceled and pending, doesn't work.

Remotipart has been working great for me in the past. I recently noticed that it has stopped working on POST/Create and PUT/Update.

No rails errors or javascript errors are generated. I can see in my console that the images are resized and uploaded correctly via Paperclip to AWS, and that Rails goes through all the follow up steps as expected, trying to render the new data.

However, nothing happens. When I look at Network activity in the Chrome I can see the post method appearing as canceled and pending in red.

I saw that this may be related to jquery 1.9+ and jquery_ujs, so I tried adding in the jquery migration script but it didn't change anything for me. It didn't look like I was on one of troubled jquery-rails versions either.

Here are some gem versions that may help:

Using rake (10.0.4)
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using aws-sdk (1.8.5)
Using railties (3.2.13)
Using rails (3.2.13)
Using fancybox-rails (0.2.1)
Using jquery-rails (2.2.1)
Using jquery-ui-rails (4.0.2)
Using paperclip (3.0.4)
Using remotipart (1.0.5)

Middleware params not working in 3.2.12

I don't know when the problem started, because it used to work for me, but with a new app using rails 3.2.12, the remotipart middleware no longer recognizes the incoming params so the Accepts header is not set properly. I will submit a fix shortly.

Request has incorrect format when it hits controller

I have an AJAX file upload with remotipart working in development.

When I use it in production, I get 406 errors because the request's format as far as the controller is concerned is text/html. In development it is text/javascript as expected.

There are two differences between development and production:

  • The two environments' different configurations (obviously!).
  • In development the app is deployed behind Pow; in production Nginx proxies through to Unicorn.

I wonder whether I need to tell Nginx to pass through any extra headers to Unicorn?

ajaxError fires under normal conditions

I have a global jQuery.ajaxError handler registered ( $('body').ajaxError() { ....} ) and remotipart causes it to be triggered under normal conditions, i.e. when a file is submitted. I think is because this gem uses:

$('form').live('ajax:aborted:file', function() ...

Just wanting to confirm this is indeed normal behaviour and wondering if there's any way to prevent it from happening.

(Thanks for this great plugin btw.)

HTML encoding messed up with remotipart

Some HTML code is messed up due to quotes and the like if AJAX is delivered through remotipart. For a demo, head over to http://shielded-savannah-6910.herokuapp.com/ and look at the encoding in the AJAX responses. Basically, if I have

<% c = '"' %>
<input type="text" value="<%= h c %>">

or

<%= text_field_tag :name, c %>

Then this HTML does not put the value attribute with a double quote if delivered through remotipart, but does the expected thing without remotipart. Remotipart should not change the default behavior of views.

The partial delivered is at https://github.com/yasirs/encoding-demo/blob/hero/app/views/application/_form_partial.html.erb

My .js.erb response displays as textarea in IE8

I'm using remotipart 1.0.2, jquery 1.6.4, jquery-rails 1.0.16, Rails 3.0.11.

I have a form uploading a file by AJAX and remotipart to my Rails app. The controller returns a .js.erb response. Everything works in Safari and Chrome, but IE8 simply displays a textarea containing my javascript (from the .js.erb).

I assumed there was a syntax error in that javascript, but when I paste it into IE8's script debugger and run it, I get simply "Object expected" (without a line number). I have Googled for this error message but haven't found anything that seems to apply. I'm not sure how else to check the javascript.

Aside from remotipart, I have ajax:success, ajax:error and ajax:complete event handlers bound to the form using live.

I'd be very grateful for any help!

Compressed Assets and Rails 3.2

This works flawlessly locally in Development, but not so much on Production... The main difference is remote and compresses assets served via CDN.... I planned to test this later tonight, but I was wondering if you would happen to know if there is an issue with compressed JS, why this acts inconsistent?

Getting conflicting status codes

Hi,

I'm having a strange issue here. I have a multipart form and everything works except when I submit a file and have a validation error in another field. When that happens, I get an HTTP 422 status, as I should, because I told it to do that, but I'm also getting the ajax:success event triggered and the xhr status code therein is 200. I'm confused!

Non-multipart forms work as expected, and so do multipart forms with no validation errors, and multipart forms with no file attached.

I circumnavigated the problem for the moment by having two forms... not ideal, but not really a huge problem.

Any thoughts?

Thanks!
-Trevor

Update is processed as HTML instead of JS

Using remotipart 1.02, Rails 3.2.11, jquery-rails-2.2.0, the file is uploaded and saved perfectly, but the request is processed as HTML instead of JS.

Started PUT "/pictures/4?attribute=image&form_element=image_field&update=picture_4_image" for 127.0.0.1 at 2013-01-31 22:26:07 -0400
Processing by PicturesController#update as HTML

Using remotipart 1.02, Rails 3.2.6, jquery-rails-2.0.2 it all works as expected:

Started PUT "/pictures/878?attribute=image&form_element=image_field&update=picture_878_image" for 127.0.0.1 at 2013-01-31 22:40:28 -0400
Processing by PicturesController#update as JS

Isn't working at all

I don't know if maybe it's something that changed in the more recent version of rails, or something with a newer version of jquery, but this gem is not working. Something is happening on the client side, the post request is not being sent via I-Frame. remotipart_submitted is never true.

Rails 3.2.8
jQuery 1.7.2

I found that if I put the latest git version of jquery-iframe-transport in my assets to override the one provided by the gem, that it works, except that the returned javascript inside the textarea tag does not get evaluated. I added a little one-liner

eval( textarea.value );

hack into the jquery-iframe-transport and I have the functionality I want now, but the gem by itself is just not working.

Remotipart without ActiveRecord possible?

Is it possible to use remotipart without ActiveRecord? For example, if my app doesn't have any database component, can I still use remotipart to maintain the files in a directory?

I'm working through the rails 3.1 sample app and getting a bit mired in the database stuff... we're not using any ActiveRecord in our app.

response isn't parsed as js - mime type issue?

I'm running Rails (3.2.8), jquery-rails (2.1.3) and remotipart (1.0.2). Any time I have a file upload in the form I receive the response, but it isn't parsed as javascript - in my inspector I receive the following:

Resource interpreted as Document but transferred with MIME type text/javascript:

I'm also not receiving an 'ajax:success' event. It's returning a 200, the post is submitted, file is saved etc. Out of ideas here...

Render override not working properly

Here's my bundle log:

Updating https://github.com/bradphelan/rocket_tag.git
Fetching gem metadata from https://rubygems.org/......
Fetching gem metadata from https://rubygems.org/..
Using rake (0.9.2.2) 
Using i18n (0.6.0) 
Using multi_json (1.3.5) 
Using activesupport (3.2.2) 
Using builder (3.0.0) 
Using activemodel (3.2.2) 
Using erubis (2.7.0) 
Using journey (1.0.3) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.3) 
Using actionpack (3.2.2) 
Using mime-types (1.18) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.4.4) 
Using actionmailer (3.2.2) 
Using arel (3.0.2) 
Using tzinfo (0.3.33) 
Using activerecord (3.2.2) 
Using activeresource (3.2.2) 
Using multi_xml (0.5.1) 
Using httparty (0.8.3) 
Using json (1.7.3) 
Using nokogiri (1.5.2) 
Using uuidtools (2.1.2) 
Using aws-sdk (1.5.1) 
Using sass (3.1.18) 
Using bootstrapped-rails (2.0.7.9) 
Using bundler (1.1.3) 
Using rack-ssl (1.3.2) 
Using rdoc (3.12) 
Using thor (0.14.6) 
Using railties (3.2.2) 
Using chosen-rails (0.9.8) 
Using cocaine (0.2.1) 
Using coffee-script-source (1.3.2) 
Using execjs (1.3.2) 
Using coffee-script (2.2.0) 
Using coffee-rails (3.2.2) 
Using dalli (2.0.5) 
Using unf_ext (0.0.4) 
Using unf (0.0.5) 
Using domain_name (0.5.3) 
Using faker (1.0.1) 
Using jquery-rails (2.0.2) 
Using kaminari (0.13.0) 
Using kgio (2.7.4) 
Using net-http-digest_auth (1.2) 
Using net-http-persistent (2.6) 
Using ntlm-http (0.1.1) 
Using webrobots (0.0.13) 
Installing mechanize (2.5.1) 
Using mysql2 (0.3.11) 
Using newrelic_rpm (3.3.4.1) 
Using pacecar (1.5.3) 
Using paper_trail (2.6.3) 
Using paperclip (3.0.3) 
Using polyamorous (0.5.0) 
Using rails (3.2.2) 
Using raindrops (0.8.1) 
Using remotipart (1.0.2) 
Using squeel (1.0.1) 
Using rocket_tag (0.3.1) from https://github.com/bradphelan/rocket_tag.git (at master) 
Using ruby-ole (1.2.11.3) 
Using sass-rails (3.2.5) 
Using spreadsheet (0.6.5.8) 
Using sqlite3 (1.3.6) 
Using to_xls (1.5.0) 
Using uglifier (1.2.4) 
Using unicorn (4.3.1) 
Using wicked_pdf (0.7.9) 
�[32mYour bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.�[0m

I've checked the code many times, it's everything in place, just like the demo show us. Actually it worked for a week, but then it stopped working and I can't seem to restore it.

I'm using remotipart to upload files. I found out that the javascript callback is not coming with that textarea data-type... thing wrapping it, and the webkit console tells it was transferred as javascript but parsed as a document (rails console points it as JS).

Don't know what to do. I'm currently trying to hardcode the <textarea> thing and see if it works.

Update. It didn't. =(

I'm in a little hurry here so I gave up remotipart and made my own iframe-ajax-uploader. Anyways I still looking forward to get this fixed.

The js result after upload does not get executed

Hello,

I am using Rails 3.0.7 and remotipart 1.0.1 with jquery-rails 1.0.19 .
Everything works just fine but after the request gets submitted the result does not get executed. I get the result surrounded by:

<textarea data-type="text/javascript" response-code="200"> ... JS code ...</textarea>

which from what I've read on the home page would need to be executed but it's not.
Can you please guide me to debugging this issue?

Thank you,
Rares

existing javascript handlers are not executed properly

Using latest rails, rails-jquery and remotipart. When using :disable_with it works when no file is selected/ uploaded in the form. When a file is selected and uploaded, the button is not disabled. It seems the jquery-rails "data-disable-with" handler is not executed anymore.

Use FileAPI when possible?

The FileAPI seems moderately well supported in modern browsers:

http://caniuse.com/#feat=fileapi

Would there be interest in getting remotipart to use the native javascript support for uploading files via XMLHttpRequest when possible, and "degrading" to the iframe version when necessary?

There are some additional nice things that could be done if the FileAPI is used (such as monitoring progress), but I assume most of us aren't quite ready to drop support for all IE users.

IE9 SCRIPT5: Access is denied.

Having this error on IE9 (jquery.iframe-transport.js line 209). I tried to use this pull request but still same thing happens. Using jquery-rails (2.1.1). Any help would greatly be appreciated.

Edit: Testing from IE9 on windows computer and server is in my computer mac.
Edit2: Also happens on IE8.

ERROR invalid body size

I worked fine with firefox and chrome but when I upload by IE8. I show issue on console:

ERROR invalid body size
Please help me solved this problem.

Code in create.js.erb not getting executed...

<textarea data-type="text/javascript" response-code="200">

var el = $('#new-category');

    $(&quot;#success&quot;).text(The category has been successfully created.);
    $(&quot;#success&quot;).removeClass(&quot;hide&quot;);
    $(el).modal('hide');

</textarea>

gets returned, doesn't get executed.

View below:

<%= remotipart_response do %>

var el = $('#new-category');

<% if @category.errors.any? %>

  var errors = $('<ul />');

  <% @category.errors.full_messages.each do |error| %>
    errors.append('<li><%= error %></li>');
  <% end %>

  // Display errors on form
  el.find('#modal-errors').html(errors);
  $("#modal-errors").removeClass("hide");
<% else %>
$("#success").text(<%= flash[:notice] %>);
    $("#success").removeClass("hide");
    $(el).modal('hide');
<% end %>

<% end %>

Running Rails 3.2.6.

Link_to remote: true not working

Im trying to use remotipart on a project, and everything is great, but, all the link_to :remote that I have stop to work. the request from those links change from JS to HTML when I added remotirpart

Im using all bleeding edge, rails 3.2.6 and ruby 1.9.3

Help please

Status bar

Hi,
is it possible to make status bar for file upload through remotipart?

We are using it for image upload and this would be nice.

Not compatible with render :collection from controller

It looks like when you use…

render :collection => @items, :partial => 'item'

…the response is not wrapped in the textarea, and each of the rendered items have the outermost element stripped off of them in JS (the response contains them, but the ajax:success data does not).

Edit: Actually, it doesn't look like it ever works. I've restarted my app, but it doesn't appear to change the situation. For whatever reason, ajax:success won't fire if I return HTML from a POST request without specifying data-type="html" on the remote form. Maybe this is related, but I'm stumped. I have yet to get Remotipart requests to respond with anything wrapped in a textarea.

And for the record, I'm using unobtrusive JS, NOT the hackish Rails 2 .js.erb views that are soon to be deprecated.

IE9 Duplicate Requests

In IE9 with a Rails 3.1.3 app (jQuery 1.7.1), I get duplicate records when submitting a form using remotipart. Has anyone experienced this?

response interpreted using wrong content type

Using latest rails, rails-jquery and remotipart.

My rails app renders a js template after the submit. When no file is selected/ uploaded in the form everything works fine.

When a file is selected/ uploaded, the response is not interpreted as javascript anymore. As the response header still shows the correct content type "Content-Type:text/javascript; charset=utf-8", I assume something in remoitpart's response handling must be wrong.

Disable buttons on forms with remotipart submit

Hello
I have some problems, not really big but rather important
All forms in my app have :disable_with param on submit buttons, but forms with remotipart loaded files are not disabling their buttons...So it looks like form is not submitting and it is not very user friendly
As I understand the thing is that form with remotipart is submited asynchronously - that's why it's not disabling. Is there any way to make this work or the only way is to disable button manually on click?

js.erb never executed?

Just setting up remotipart for the first time with an existing rails 3.2 project. I'm using a similar setup for ajax that is described here: http://www.alfajango.com/blog/rails-3-remote-links-and-forms-data-type-with-jquery/

Trying out remotipart, my file is uploaded fine and my page gets a response back. I get an event for ajax:complete that has my js.erb response in the xhr.responseText.

The problem is that response js is never executed in the client browser. My impression is that it should be executed. Is that not correct? I can't find any documentation that shows how this should be handled. Apologies if I missed it.

Thanks!

Params hash created doesn't include buttons

Hi,

I've got a form that contains a few buttons that controll various actions in the controller. In rails_ujs the clicked button is registered by the following code

$(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
  var button = $(this);
  if (!rails.allowAction(button)) return rails.stopEverything(event);

  // register the pressed submit button
  var name = button.attr('name'),
  data = name ? {name:name, value:button.val()} : null;
  button.closest('form').data('ujs:submit-button', data);
})

Now there's a function called handleRemote in jquery_ujs that sets

data = element.serializeArray();
// memoized value from clicked submit button
var button = element.data('ujs:submit-button');
if (button) {
data.push(button);
element.data('ujs:submit-button', null); 

where element is the submitted form und data the array to generate the params hash from. The problem is the last line, where 'ujs:submit-button' is set to null, so I don't have access to it later. So I tried this in my fork of remotipart, which failed:
At the top I added

$(function() {
  $(document).delegate(rails.formInputClickSelector, 'click.rails', function(event) {
  var button = $(this);
  if (!rails.allowAction(button)) return rails.stopEverything(event);
  // register the pressed submit button
  var name = button.attr('name'),
  data = name ? {name:name, value:button.val()} : null;
  button.closest('form').data('ujs:remotipart-submit-button', data);
  }); 
});

and a few lines further down

settings.files       = $($.rails.fileInputSelector, form);
settings.data        = form.serializeArray();
var button = form.data('ujs:remotipart-submit-button');
if (button) {
  settings.data.push(button);
  form.data('ujs:remotipart-submit-button', null);
}

This doesn't work and I wonder why. Is it a bug in the remaining javascript or do I get the meaning of the "delegate" method wrong?

Response not executing

I'm probably using this wrong, but if I submit an empty file (just clicking upload without a file in the upload field) the js in the response executes - (the response being "alert('uploaded')". If I actually upload a file I get HTML in the response and it doesn't execute, instead I get the following response:

<!DOCTYPE html><html><body><textarea data-status='200' data-statusText='OK' data-type='text/html'><textarea data-type="text/javascript" response-code="200">alert('uploaded.');
</textarea></textarea></body></html>

If it helps, the form doesn't relate to any model, I am attempting to use it to upload a csv file via ajax, and then append the contents of it to a textarea.

Received response contains bits of html

When I submit the form using .ajax with dataType: 'script', the server returns a javascript function in create.js.erb which being merged with soem HTML i.e.

jquery(...)

Any idea how to solve this?

js.erb file is not fired up when try upload a image

I have inside a fancybox box this form:

<%= simple_form_for(@message, :remote => true, :html => {:multipart => true}, :url => { :controller => "users/messages", :action => "create"} ) do |f| %>
 <%= f.error_notification %>
 <%= f.input :subject, :input_html => { :maxlength => 500} %>
 <%= f.input :message_image, :as => :file %>
 <%= f.button :submit, t('.send_message'), :class => 'btn-large btn-primary', "data-disable-with" => t('.send_message'), :confirm => t('.sure_send_message') %>
<% end %>

This is my create action:

def create
 @message = Message.new(params[:message])
 respond_to do |format|
  if @message.save
   format.js { render :partial => "users/messages/templates/sent_by_user/create" }
  else
   format.js { render :partial => "users/messages/templates/sent_by_user/nosave" }
  end
 end 
end

The files create.js.erb or nosave.js.erb file is working fine if I don't try upload a image

If I try upload a image this files is not rendered.

However in my log I can see:

Processing by Users::MessagesController#create as JS
  Parameters: {"message"=>{"message_image"=>#<ActionDispatch::Http::UploadedFile:0xf7a85c8 @original_filename="cara_enfadada.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"message[message_image]\"; filename=\"cara_enfadada.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20121015-21710-6oxtn2>>, "subject"=>"estrella de neutronessssssssssss"}, "commit"=>"Enviar mensaje", "utf8"=>"✓", "authenticity_token"=>"mfSsl0HafWoW86YiO2Hj7zMepAITZlHHBtUqW0wzubU=", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "locale"=>"es"}

and

Rendered users/messages/templates/sent_by_user/_nosave.js.erb (0.2ms)
Completed 200 OK in 498ms (Views: 1.5ms | Solr: 0.0ms)

On google chrome console I get the next alert:

Resource interpreted as Document but transferred with MIME type text/javascript:

I'm using remotipart gem but I dont find the error...
Where is the error?
Thank you

ajax:success callback not being called

I'm using rails 3.2.6 and the last version of remotipart. The ajax:success callback is not being being called when the form is submitted. Right now i'm using ajax:complete to make the functionality work

conflict with gem jquery-fileupload-rails

when I include gem jquery-fileupload-rails and use its middleware, my server response becomes

<!DOCTYPE html><html>
<body><textarea data-status='200' data-statusText='OK' data-type='text/html'>
<textarea data-type="text/javascript" response-code="200">
...lines of jquery code...
 </textarea>
</textarea></body></html>

then the js code was not evalutated.
jquery-fileupload-rails middleware wrap a new textarea tag which generated by https://github.com/tors/jquery-fileupload-rails/blob/master/lib/jquery/fileupload/rails/middleware.rb#L25
and broken remotipart.
I don't think it's a problem of remotipart. and I create the issue to help other guys who blocked on this problem and it should be closed later.
But I curious why set response.content_type = Mime::HTML in https://github.com/JangoSteve/remotipart/blob/master/lib/remotipart/render_overrides.rb#L17

html escape

Hi. I write the code so can not speak English.

controller

render :js => "alert('& &amp; > &gt; < &lt; \" &quot;')"

response.body

<textarea data-type="text/javascript" response-code="200">alert('&amp; &amp; &gt; &gt; &lt; &lt; &quot; &quot;')</textarea>

alert

& & > > < < " "

edit lib/remotipart/render_overrides.rb

# response.body = %{<textarea data-type=\"#{content_type}\" response-code=\"#{response.response_code}\">#{escape_once(response.body)}</textarea>}
response.body = %{<textarea data-type=\"#{content_type}\" response-code=\"#{response.response_code}\">#{ERB::Util.h(response.body)}</textarea>}

response.body

<textarea data-type="text/javascript" response-code="200">alert('&amp; &amp;amp; &gt; &amp;gt; &lt; &amp;lt; &quot; &amp;quot;')</textarea>

alert

& &amp; > &gt; < &lt; " &quot;

Uncaught TypeError: Object [object Object] has no method 'ajaxSubmit'

Hi, I'm under rails 3.2.1 with jquery 1.7.1 and I get this error when I try to submit a form

Uncaught TypeError: Object [object Object] has no method 'ajaxSubmit'

here my js include

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require jquery.remotipart
//= require twitter/bootstrap

and my form

  = form_for VideoInterview.new, :url => video_interviews_path, :html => { :class => :form, :multipart => true }, :remote => true do |f|
.showitem
  = f.label :title, t("activerecord.attributes.video_interview.title", :default => "Title"), :class => :label
  .input
    = f.text_field :title, :class => 'text_field'
.showitem
  = f.label :title, t("activerecord.attributes.video_interview.file"), :class => :label
  .input
    =f.label :file
    = f.file_field :file
.clearF
.separator
.form-actions
  %button{:class => "btn primary", :type => "submit"} Save

any hint?

Cross domain?

I'm trying to move my file upload processing into a separate Rails app at a different subdomain.

Unsurprisingly, my initial attempt of changing the URL of the upload form to the new subdomain hasn't worked (getting cross domain errors in the Safari console).

Any thoughts on how to get this working with Remotipart?

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.