tansengming / stripe-rails

A Rails Engine for integrating with Stripe
MIT License
753 stars 123 forks source link

Problem: NameError when loading JavascriptHelper #217

Closed yrashk closed 1 year ago

yrashk commented 2 years ago

I've encountered the problem while upgrading to Rails 7 and found this solution in one of the issues (#168). Don't think this is the best solution but it got me past the problem. Any suggestions on how we can fix this better?

tansengming commented 2 years ago

Hi @yrashk thanks for the PR. I just had another look at https://github.com/tansengming/stripe-rails/issues/168 and tried to recreate the issue with a minimal installation of rails

> bundle exec rails console
Loading development environment (Rails 7.0.2.4)
irb(main):001:0> pp Stripe::Engine.helpers_paths
["/Users/tansengming/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/stripe-rails-2.3.3/app/helpers"]
=> ["/Users/tansengming/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/stripe-rails-2.3.3/app/helpers"]
irb(main):002:0> pp Stripe::JavascriptHelper
Stripe::JavascriptHelper
=> Stripe::JavascriptHelper

Unfortunately I cannot reproduce the NameError you're seeing. Based on the output of pp Stripe::Engine.helpers_paths it looks like the path is getting set up correctly without your patch.

So I'm stumped!

I appreciate that you got the gem working with the patch but I want to be cautious about adding code without figuring out. Based on feedback on https://github.com/tansengming/stripe-rails/issues/168 it still looks like some other gem is messing up ... something. Can you have a check to see which other gem is trying to load JavascriptHelper ?

smtlaissezfaire commented 1 year ago

@tansengming You have to set:

config.active_support.deprecation = :stderr in your development.rb (or view the logs) to see it.

That's what its set to in test.rb so you should see it in test when running spring (you'll need to stop spring to see it).

tansengming commented 1 year ago

@smtlaissezfaire thanks for the tip!

Unfortunately I was still not able to replicate it. Things I have tried:

However even though I was not able to replicate this, I decided to merge https://github.com/tansengming/stripe-rails/pull/220 based on feedback from @chrisyuska and https://bill.harding.blog/2021/07/22/rails-6-1-deprecation-warning-initialization-autoloaded-the-constants-what-to-do-about-it/

FYI @yrashk the fix on https://github.com/tansengming/stripe-rails/pull/220 should fix this!