hi5dev / google-webfonts

Provides a helper for using Google Webfonts in a Rails application.
MIT License
28 stars 16 forks source link

Uninitialized constant Mime::CSS (google-webfonts 0.2.0) #11

Closed Themayu closed 6 years ago

Themayu commented 6 years ago

What is the error?

When attempting to execute the google_webfonts_link_tag helper, a NameError is raised on the calling line with the message uninitialized constant Mime:CSS.

Where does the error occur?

The error occurs in the below code snippet (lines 17 to 22, line numbers added manually):

17    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
18
19    <%= google_webfonts_link_tag :open_sans => 400,
20                                 :roboto => 400 %>
21  </head>
22

(Application trace gives output: app/views/layouts/application.html.erb:19:in '_app_views_layouts_application_html_erb___976211659525133562_38888580')

Environment

I am using an install of Ubuntu version 16.04.04 LTS via the Windows Subsystem for Linux with Ruby 2.4.1 and Rails 5.1.6, installed with RVM 1.29.3.

Themayu commented 6 years ago

Full trace gives the following:

google-webfonts (0.2.0) lib/google-webfonts/link_tag.rb:47:in `link_options'
google-webfonts (0.2.0) lib/google-webfonts/link_tag.rb:14:in `initialize'
google-webfonts (0.2.0) lib/google-webfonts/helper.rb:40:in `new'
google-webfonts (0.2.0) lib/google-webfonts/helper.rb:40:in `google_webfonts_link_tag'
app/views/layouts/application.html.erb:19:in `_app_views_layouts_application_html_erb___976211659525133562_38888580'
actionview (5.1.6) lib/action_view/template.rb:157:in `block in render'
activesupport (5.1.6) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.1.6) lib/action_view/template.rb:352:in `instrument_render_template'
actionview (5.1.6) lib/action_view/template.rb:155:in `render'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:64:in `render_with_layout'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:50:in `render_template'
actionview (5.1.6) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (5.1.6) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (5.1.6) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (5.1.6) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.1.6) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (5.1.6) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.1.6) lib/action_controller/metal/renderers.rb:141:in `render_to_body'
actionpack (5.1.6) lib/abstract_controller/rendering.rb:24:in `render'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (5.1.6) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/*****/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
activesupport (5.1.6) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (5.1.6) lib/action_controller/metal/implicit_render.rb:33:in `default_render'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `block in send_action'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `tap'
actionpack (5.1.6) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:186:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.1.6) lib/active_support/callbacks.rb:131:in `run_callbacks'
actionpack (5.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `block in instrument'
activesupport (5.1.6) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.1.6) lib/active_support/notifications.rb:166:in `instrument'
actionpack (5.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.1.6) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
actionpack (5.1.6) lib/abstract_controller/base.rb:124:in `process'
actionview (5.1.6) lib/action_view/rendering.rb:30:in `process'
actionpack (5.1.6) lib/action_controller/metal.rb:189:in `dispatch'
actionpack (5.1.6) lib/action_controller/metal.rb:253:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:31:in `serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in `call'
rack (2.0.4) lib/rack/etag.rb:25:in `call'
rack (2.0.4) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.4) lib/rack/head.rb:12:in `call'
rack (2.0.4) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.4) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.6) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.6) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.6) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.4) lib/rack/method_override.rb:22:in `call'
rack (2.0.4) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.6) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
railties (5.1.6) lib/rails/engine.rb:522:in `call'
puma (3.11.3) lib/puma/configuration.rb:225:in `call'
puma (3.11.3) lib/puma/server.rb:624:in `handle_request'
puma (3.11.3) lib/puma/server.rb:438:in `process_client'
puma (3.11.3) lib/puma/server.rb:302:in `block in run'
puma (3.11.3) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

(Username has been blanked out for privacy reasons)

travishaynes commented 6 years ago

@Themayu I've removed the ActionPack dependency from the gem. It no longer uses any Rails internals to generate the link tags. Try updating to the latest version, and let me know if you still get the error. If not, just close this issue.

Themayu commented 6 years ago

Attempting to launch Rails after having updated google-webfonts and modified my Gemfile as directed in README.md now causes Rails to fail with the following error:

/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:84:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'google/webfonts/rails'. (Bundler::GemRequireError)
Gem Load Error is: private method `define_method' called for Google::Webfonts::LinkTag:Class
Did you mean?  redefine_method
               re_define_method
Backtrace for gem load error is:
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/google-webfonts-0.3.1/lib/google/webfonts/rails.rb:8:in `<top (required)>'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `require'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
/home/*****/proj/zifar/web_interface/config/application.rb:17:in `<top (required)>'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:133:in `require'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:133:in `block in perform'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `tap'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `perform'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke'
/home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands.rb:16:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Bundler Error Backtrace:
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:80:in `block (2 levels) in require'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
        from /home/*****/proj/zifar/web_interface/config/application.rb:17:in `<top (required)>'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:133:in `require'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:133:in `block in perform'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `tap'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `perform'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke'
        from /home/*****/.rvm/gems/ruby-2.4.1@zifar/gems/railties-5.1.6/lib/rails/commands.rb:16:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'
travishaynes commented 6 years ago

@Themayu Version 0.3.2 of the gem is now compatible with Ruby 2.4.1. Just update to that and it should work.

It looks like they changed define_method from a private to public method between version 2.4.1 and 2.5.0, which is what the tests were designed for. So I just removed the use of define_method. I also updated .travis.yml so it will test against Ruby 2.4.1 in the future.