winston / google_visualr

A Ruby Gem for the Google Visualization API. Write Ruby code. Generate Javascript. Display a Google Chart.
http://googlevisualr.heroku.com
MIT License
428 stars 100 forks source link

Fixed Railtie to only load helper for UI controller #121

Closed bkuhlmann closed 2 years ago

bkuhlmann commented 3 years ago

Overview

Necessary to prevent the following error when a Rails application is initialized and uses the ActionController::API for a base class:

NoMethodError:
  undefined method `helper_method' for ActionController::API:Class
# $HOME/.gem/ruby/2.7.3/gems/google_visualr-2.5.1/lib/
  google_visualr/app/helpers/view_helper.rb:7:in `block in
  <module:ViewHelper>'

Normally, when configuring Rails, you can specify if your application is API or UI only (UI is the default) and Rails will auto-filter initializers which don't support the one or the other. In my case, I'm working with a Rails app that is a hybrid of UI and API functionality. Unfortunately, the :action_controller hook is a superset hook which causes issues. Here's a better illustration:

This is why applying this fix ensures the Google view helper isn't loaded for API purposes. 😉

Notes

I'm afraid I wasn't able to write a spec for this because the Bundler and Appraisal gems are quite outdated on this project. If I had more time, I'd fix that too but wanted to get this up for review in case there is interest and of help to others.

bkuhlmann commented 2 years ago

:information_source: Closing this down since this has been open for over a year and I'd like to get my Inbox back to zero.