-
Notifications
You must be signed in to change notification settings - Fork 648
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
wicked_pdf and remotipart gems can't coexist #111
Comments
Yes, it looks like both of our projects muck with
This should let you use them both together until I get a proper fix together. I was never really a fan of the alias_method chaining anyway... |
Played around with it tonight for a bit. Got it working on Rails 3.2.3 with: if ::Rails.version < "3.1"
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
else
def self.included(base)
base.class_eval do
after_filter :clean_temp_files
end
end
ActionController::Renderers.add :pdf do |obj, options|
log_pdf_creation
options[:basic_auth] = set_basic_auth(options)
options.delete(:pdf)
make_pdf((WickedPdf.config || {}).merge(options))
end
end and ...
html_string = render_to_string(:template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :prefixes => options[:prefixes])
... I won't bother committing this exactly because I'm too new to the Rails community to know if this is the best backwards compatible way to do it, and I haven't fully considered if its best to move the disposition/filename stuff to be the responsibility of the calling controller (though I think it is). |
I have forked a branch to use in our project using David's suggestion, I am wondering when can we have the official fix in wicked_pdf in the near future. Thank you for your good work! |
Applying solution presented in mileszs#111 (comment)
I have the same issue with Turbolinks. Turbolinks is also overriding render and when I add wicked_pdf gem that override stops working. Commenting out self.included (as mentioned above) works but I would like to avoid using forked library just because of this issue. Since Turbolinks is kinda official rails lib (they are really pushing it) I would try to come up with a solution for this. I'm not a ruby developer so I can't really help much :/ |
+1 We use the forked branch and have to avoid updating the gem due to this issue. |
This should be solved with the merge of #574 Please reopen if there are any further issues after upgrading. |
Hi there, I see this problem popping up again with wicked_pdf 2.0.1 and remotipart 1.4.x. If I downgrade to wicked_pdf 1.4.0, the problem disappears. Best |
The only thing that I can see that could be causing this for you is this change: https://github.com/mileszs/wicked_pdf/compare/1.4.0..2.0.1#diff-ea9340aeb7bd0bcc5782373373980c56R9 introduced in #869 I think maybe the deferring of loading makes it so that remotipart again get loaded first, causing render issues. My plan for wicked_pdf version 3 is to stop mucking with render entirely, but it's a big change to the API surface. Until then, you should be able to do something like this: #111 (comment) or roll back to the working version. I do plan on working to fix this soonish, but it'll still likely be awhile before it's released unless you, or someone else, can help. |
First thank you for the prompt reply. I agree the only change that could explain the new behavior would be there: I don't know enough the mechanism of ActiveSupport.on_load to understand why it was needed to be compatible with Rails 6 but I agree the deferred loading could explain that remotipart is registered first. For my culture, if someone could explain what is the interest of the deferred loading, I would appreciate. Performance? |
If a reference to This is due to an issue with loading classes in an initializer which are managed by the autoloader. Classes referenced in an initializer will be lost when they are reloaded.
Why are the |
Thanks, I will give it a try when the new version of the gem is out! I look forward to it! |
TL;DR Update your
I was previously using skillstream@c8c09fa to allow However to address [the Rails] rails (~> 6.0.3.7)
I fixed the issue locally in the gem code located at
I've tested the Changes to
Once a new release of |
I don't have the depth of expertise to identify if one or both projects are doing something inadvisable, so I'm posting this on both projects in the hope that someone more knowledgeable will be able to point out a fix to one or both parties. At the very least, these gems don't seem to play well together.
Both gems mess with the render method in ActionController::Base. wicked_pdf does method chaining and remotipart does it by calling super.
When wicked_pdf and remotipart are both loaded in the Gemfile part of remotipart ceases to function.
See JangoSteve/remotipart#27 for more details.
The text was updated successfully, but these errors were encountered: