Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The js result after upload does not get executed #12

Closed
laleshii opened this issue Dec 8, 2011 · 18 comments
Closed

The js result after upload does not get executed #12

laleshii opened this issue Dec 8, 2011 · 18 comments

Comments

@laleshii
Copy link

laleshii commented Dec 8, 2011

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

@bjensen
Copy link

bjensen commented Dec 9, 2011

I think I have the same issue...I have a remoti_response block in my create.js.erb file. I can see using firebug that the contents I get returned is valid js, but is is not being evaluated by the browser as if the dataType isnt set to script..

Im using remotipart master. Rails 3.0.9 and jquery-rails 1.0.19

@bjensen
Copy link

bjensen commented Dec 10, 2011

Here is what my form submit looks like:

Started POST "/account?id=1418" for 127.0.0.1 at 2011-12-10 12:02:57 +0100
Processing by StudentsController#update as JS
Parameters: {"user"=>{"photo"=>#<ActionDispatch::Http::UploadedFile:0x007f8479e223e0 @original_filename="claus forstander.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name="user[photo]"; filename="john.jpg"\r\nContent-Type: image/jpeg\r\n", @tempfile=#File:/var/folders/k6/sf3hfpg93xdcfktpk4m8v2lh0000gn/T/RackMultipart20111210-25826-c6dkeo>}, "utf8"=>"✓", "authenticity_token"=>"wKNI8hhauzwSoYVr7V4T5gABZXIXlid5W0WRWQV+zaE=", "stay_id"=>"23", "user_id"=>"1418", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, /; q=0.01", "id"=>"1418"}
...
...
...
Rendered students/update.js.erb (56.9ms)

@laleshii
Copy link
Author

I see nobody watches the issues on this project.
I finally found out what the problem is. It seems nested escape_javascript does not work when the result is executed using the iframe method.

I have the following code in the create/update js:

$('#contenttext').html('<%= escape_javascript(render "form", :content => @content,:content_text => @selected_ctext ) %>');

and in the _form partial I have this link added:

def link_to_add_fields(name, f, association)
   new_object = f.object.class.reflect_on_association(association).klass.new
   fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
      render(association.to_s.singularize + "_fields", :f => builder)
   end
   link_to_function(name, "add_fields(this, '#{association}', '#{escape_javascript(fields)}')") 
end

This works when I do not upload any file but fails when I do.

@bjensen
Copy link

bjensen commented Dec 12, 2011

laleshii What if you just put this into your create.js.erb:

<%= remotipart_response do%>
alert("hello world");
<% end %>

Does that then work?

@laleshii
Copy link
Author

Yes that works properly.

I downloaded the test application and tried to see what were the differences. From what I've seen it was only that I used "" wrappers and not ''. After I replaced everything I could it worked partially. It works now besides the above auto generated link which auto generates the code with "" wrappers.

@laleshii
Copy link
Author

This is not a issue it's a bug in the way the result is rendered.

You can try for yourself. Put this in a form response which uses remotiform for AJAX file upload and you will see the result only gets properly rendered you don't upload anything and the classic js response is used.

http://pastebin.com/Ah5MdFav

@bjensen
Copy link

bjensen commented Dec 16, 2011

Im working on demo project that will demonstrate the bug. Ill put it on github and share the url

@laleshii if you attach a file does it then send a HTML request and a JS request if you dont? That is my problem.

update: If I use my simple demo project then it works fine, however if I use it in a client project with over 30 gems then it is messing up, as if some other gem is conflicting. I hope @JangoSteve will look into this issue as well..

My demo project is here: github.com/bjensen/remotipart_bug and it works fine. I need to experiment by adding more gems to the project to see which gem is causing the conflict.

@bjensen
Copy link

bjensen commented Dec 17, 2011

I finally figured it out my issue!

It was a conflict with wicked_pdf, once I removed that from my Gemfile things were running smoothly. I am not sure yet why this is the case but Ill keep digging.

@laleshii are you using wicked_pdf in your project? What happens if you use my demo project? If your not using wicked_pdf and your still getting errors then maybe you should do as me and remove gems while testing if the functionality of remotipart works.

@terrell
Copy link

terrell commented Dec 24, 2011

@bjensen In my application, I can confirm the same issue you found and also that removing wicked_pdf resolves the issue.

Too bad that I need wicked_pdf though, so I'm still working on finding a solution.

@0xradical
Copy link

Hi @bjensen , the issue is both wicked_pdf and remotipart override the render method in some way: wicked_pdf through alias_method_chain and remotipart overrides render through "module inheritance", thus one of the render doesnt get called:

class A1
 def meth
  puts 'a1'
 end
end

class A2
  def meth
    puts 'a2'
  end
end

module B
  def self.included(base)
    base.class_eval do
      alias_method_chain :meth, :feature
    end
  end
  def meth_with_feature
    puts 'b'
    meth_without_feature
  end
end

module C
  def meth
    puts 'c'
    super
  end
end

A1.send :include, B
A1.send :include, C

A2.send :include, C
A2.send :include, B

puts A1.new.meth
# b
# a1
puts A2.new.meth
# b
# a2

they dont talk to each other ...

@bitboxer
Copy link

@thiagobrandam I tried your fork, but that is not fixing that issue for me.

@0xradical
Copy link

@bitboxer if you disable wicked_pdf and use the official remotipart gem, it does work, right? My fork works for me, so I don't know what could be happening, maybe there's some edge case I overlooked when I forked...

@bitboxer
Copy link

No, I am not using wicked_pdf in my project. But I see the same problem @laleshii is reporting. I see the textarea, but the code is not executed. I think there are more problems with this than the problem with wicked :( .

@0xradical
Copy link

@bitboxer I see ... My guess is that there is another gem causing you trouble, I suggest you disable all your gems one by one and test remotipart each time until it works.

@JangoSteve
Copy link
Owner

Any news on this? The specs pass and it works fine in the example app. I'm guessing it's not remotipart.

@JangoSteve
Copy link
Owner

Closing the issue, let me know if it needs to be reopened.

@terrell
Copy link

terrell commented Mar 26, 2012

To anyone else still experiencing this issue with wicked_pdf, you may try switching to wisepdf.

I recently switched to wisepdf and everything appears to work as it should now.

@notmatthancock
Copy link

Thank you!! I had this issue and removing wickedpdf resolved my issues as well.

Has anyone got wickedpdf and remotipart working friendly and could elucidate on what needs to be done to do so?

In the mean-time I will look into wisepdf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants