From ed0b864bc972af7af18043ac8ecfe2f3d4f8bb3d Mon Sep 17 00:00:00 2001 From: Ryusuke Homma Date: Sat, 11 Mar 2017 10:08:02 +0900 Subject: [PATCH] Fix NameError Mime::JS in Rails 5.1.0 beta * ::Mime::JS is deprecated in Rails 5.0.x and removed in 5.1.0 beta. Instead of using ::Mime::JS, ::Mime[:js] is recommended. So I use this. * But in Rails 2.3, ::Mime[] is not defined and raise NoMethodError. So I check that ::Mime[] is defined using respond_to?, and if not defined, then use ::Mime::JS. --- lib/wicked_pdf/wicked_pdf_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/wicked_pdf/wicked_pdf_helper.rb b/lib/wicked_pdf/wicked_pdf_helper.rb index 189cf048..dea4f1d3 100644 --- a/lib/wicked_pdf/wicked_pdf_helper.rb +++ b/lib/wicked_pdf/wicked_pdf_helper.rb @@ -23,8 +23,9 @@ def wicked_pdf_image_tag(img, options = {}) def wicked_pdf_javascript_src_tag(jsfile, options = {}) jsfile = WickedPdfHelper.add_extension(jsfile, 'js') + type = ::Mime.respond_to?(:[]) ? ::Mime[:js] : ::Mime::JS # ::Mime[:js] cannot be used in Rails 2.3. src = "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}" - content_tag('script', '', { 'type' => Mime::JS, 'src' => path_to_javascript(src) }.merge(options)) + content_tag('script', '', { 'type' => type, 'src' => path_to_javascript(src) }.merge(options)) end def wicked_pdf_javascript_include_tag(*sources)