leppert/remotipart

remotipart not working with latest jquery-ujs

Closed this issue · 29 comments

The jquery-ujs folks they did a big refactoring, changing the method "callRemote" which remotipart hooks to, to "handleRemote" and thus breaking remotipart.

This is the commit of their refactoring: rails/jquery-ujs@c592fb7

Also wanted to point out that as says in jquery-ujs refactoring commit, they stopped using $.fn.extend, so it seems that jquery.remotipart.js will have to use an alternative way to hook to jquery-ujs:

  • jQuery.fn is not augmented with extra methods anymore

Thanks for the heads up; this is definitely an issue. I've added a note to the README.rdoc for people to use the version of jquery-ujs that comes with the current gem for the time being and I'll write up a fix in the next few days. I should be able to listen for ajax:beforeSend and use that as a trigger rather than the current method.

Hey, let me know if you'd like any help with this. I've been helping a bit here and there with the latest jquery-ujs driver, and have a good idea for getting this working with it.

It would be great if you fixed this issue

For anyone who needs it now, I got remotipart working with the latest jquery-ujs. I'm not submitting the patch to be integrated back in yet, because it relies on a patch I had to make to the jquery-ujs. I'm fairly certain I can get the patch accepted back into core rails, at which point, I can submit the remotipart patch here.

In the meantime, you can get this working by using my forks from each project (again, only a temporary solution).

  1. Replace rails.js with this version.

  2. Put this in your Gemfile:

gem 'remotipart', :git => 'git://github.com/JangoSteve/remotipart.git', :branch => 'latest-and-greatest'
  1. Run bundle install and then rails g remotipart.

Works like a charm - thank You! :)

Hi let me know any one can help on this

This gem works fine but while using in rjs
this is my case
page.redirect_to :action=>"index", :controller =>"semails", :user_id => current_user.id

i'm getting params [:attachment] and also file saved in the db but not redirecting to the specific action

This is my form tag html.erb page

<%=form_for :semail, :url => user_semails_path(:format => 'js'), :remote=>true,:html => {:name=>'form_semail', :id=>'form_semail', :multipart => true, :target => 'upload_frame',:class => 'emails_new_content'} do |form| -%>

<%=fields_for :attachment do |file_form| -%>


<%= file_form.file_field :data, :size=>30 %>


<% end -%>

rjs page
if (@serror.empty? && @ssubject_error.empty? && from.nil?)
page << "loadingPanel.hide();"

if !@doctor.blank?
page.redirect_to :action=>"sprofile", :controller =>"sdoctors", :id => @sdoctor.id
else
page.redirect_to :action=>"sindex", :controller =>"semails", :suser_id => current_user.sid
#redirect_to :action=>"sindex", :controller =>"semails", :suser_id => current_user.sid
end
elsif (@serror.empty? && @ssubject_error.empty? && from.to_s == "email_popup")
page << "loadingPanel.hide();"
page << "Modalbox.hide();"

elsif (!@ssubject_error.empty?)
page << "loadingPanel.hide();"
page << "$('errmsg').innerHTML='#{escape_javascript(@ssubject_error)}'; new Effect.Appear('errmsg');"
else
page << "loadingPanel.hide();"
page << "$('errmsg').innerHTML='#{escape_javascript(@serror)}'; new Effect.Appear('errmsg');"
end

in the controller
respond_to do |format|
if params[:sent_type] == "sreply" || params[:sent_type] == "sforward"
format.js do
render :action => 'sreply_email_response'
end
else
unless params[:sdoctor_id].blank?
@sdoctor =Sdoctor.find_by_id(params[:sdoctor_id])
end

    format.js do
      render :action => 'ssend_email_response'
    end
  end
end

attachment save in the db but page not redirecting

what is the issue in my case

I'm not sure, I haven't used RJS in a long time (it's typically fallen out of favor, we try to just stick with JS.ERB now). But I would follow my steps outlined here in this issue to debug the problem.

The latest Rails 3.0.5 fix a bug with certain cases of session blanking on AJAX calls due to invalid authenticity token. I upgraded to Rails 3.0.5 to fix this bug and rails.js was updated as well. Of course this breaks remotipart but if I regress to rails.js you link it brings back the session blanking invalid authenticity token bug.

Can you update your rails.js to accomidate rails 3.0.5?

Hey jdodson, sure thing, it's updated and pushed now.

Awesome, that works thank you!

What's the latest on updating this to work with re-factored UJS?

Hey andrewtheis, I just updated my fork with the latest from jquery-ujs master, so you should be able to follow my instructions here again.

As an update, my fork has two updates applied to the jquery-ujs. One of them was just accepted into core last week, and the other is tagged to be looked at next. So, hopefully Remotipart will soon work natively with jquery-ujs once again.

Thanks! This worked, however my js.erb files aren't being executed once the upload finishes (well rails says they are, but nothing happens).

I'm running latest remotipart, rails.js driver you linked to in the earlier comment, and jQuery 1.5

Has something else changed with remotipart/UJS? Here is the code that should be executed (strangely the file upload and everything happens, just no callback happens to the page).

<%= remotipart_response do %>
<% if notice %>
$("#flashnotice").html('

<%= escape_javascript(flash.delete(:notice)) %>
');
$("#screenshots").append("<%= escape_javascript render(:partial => @screenshot) %>");
$("#new_screenshot")[0].reset();
add_ajax_to_delete_buttons();
<% elsif alert %>
$("#flashnotice").html('
<%= escape_javascript(flash.delete(:alert)) %>
');
<% end %>

$("#add_screenshot_loading").css({"display":"none"});

<% end %>

Nothing has changed. What is actually being rendered as the response? Try following this article and seeing if it's just a JavaScript error.

This is the error:

$.handleError is not a function
[Break On This Error] $.handleError(s, xhr, 'error', e);

Line 388 in jquery.form.js

It looks like this is a known jquery.form.js bug. Are you using an old version of form.js? See this issue.

Ah yup that was it. Thanks!

git://github.com/JangoSteve/remotipart.git (at latest-and-greatest) is not checked out. I am getting this error while installing. any solution for this?

Also if I replace the rails.js, all the link_to with :remote => true fail.

Hey Srinivas, it sounds like something is messing up with your bundler gem, in trying to checkout the git repository. Is your bundler version out of date? Also, try maybe starting over, following the instructions from this wiki.

yup followed the instructions from the wiki page. Let me check my bundler. All the other gems seem to work fine. Problem only when I specify the path.

I think it is a configuration issue with bundler, trying to install the gem from a git repo (do you have any other gems that are installing from a git repo?). I found this issue ticket for bundler, perhaps the answer lies in there.

Hey thanks a lot. I just went to the site and everything works like a charm! Amazing gem especially for people like me who are weak with javascript.

About the bug - I just did bundle install and got permission denied error. Then I did sudo bundle install(the usual thing). Solved the issue. I was doing sudo bundle install all this while. I don't know how the bug got resolved. Will think about later. Everything works like charm now. Thanks for all the help.

Support for latest rails.js Interactive should be added :)

Working on it now. Trying to organize some other things (making it easy to figure out which version of the gem to use with whatever version of jquery-ujs you have) in the process.

FYI, I have just updated Remotipart to v0.3.2, which adds support for rails.js versions up to 7f2acc1811f62877. See the updated README for more info.

Forthcoming is compatibility for the current rails.js.

I've now pushed versions 0.3.3 and 0.3.4 of Remotipart. We now have versions of Remotipart which are compatible with any version of rails.js you could possibly have. See the compatibility chart in the README.

So sound the trumpets and fetch the dancing ladies. With the release of v0.3.4, Remotipart is finally compatible with the latest jquery-ujs.

Great, thanks!! :)