2

In my Rails app Gemfile, I have gem 'myfancygem', path: '/Users/matt/myfancygem'

This works as you'd expect.

I then added a configuration block feature to the gem, a la https://robots.thoughtbot.com/mygem-configure-block (and many others out there that are slight variants on this)

I created an initializer myfancygem.rb in my Rails app with the standard: Myfancygem.configure do |config| config.favorite_color = 'red' end

When running my local app (either in rails console, or rails server), that favorite_color does NOT get set. It remains at the default specified inside the gem (nil)

But if I push that gem to rubygems and load it normally (i.e. without the path bit in the Gemfile), the initializer config works as expected.

Just in case I was doing something nutty in my gem, I git cloned the latest copy of the ReactOnRails gem, which does pretty much the same configuration approach. Then I pointed my Gemfile at the local ReactOnRails via path. Guess what? SAME PROBLEM. The initializer I setup for my Rails app for ReactOnRails seems to be ignored. I even sprinkled puts statements into the initializers to prove they were getting executed and the configuration was being set, but then it would reset back to defaults right after Rails.application.initialize! in environment.rb

Ummm... what the heck?

Is this a known bug in Rails? Or Bundler? or something? Or is there some gotcha I'm missing? Or something I could have done wrong that I'm not realizing?

mepatterson
  • 143
  • 1
  • 7
  • Especially in the beginning you should avoid forking and changing working gems. – Simon Franzen Mar 06 '18 at 01:01
  • Restarted server ? – Simon Franzen Mar 06 '18 at 01:01
  • 1
    To be clear, the point of the question was a strange behavior I'm seeing in a local Rails app using a local gem via the `path` parameter in the Gemfile. When building a new gem to work against a Rails app's API endpoints (that I also built), it's helpful to be able to hook the gem up via the app's Gemfile using `path` instead of constantly having to push it to a remote server. And that's when I discovered that my app-side configuration wasn't taking, but would work fine if not using the `path` in Gemfile. That's what is confusing me... tried restarting server, tried killing Spring, etc... – mepatterson Mar 06 '18 at 19:43
  • ok thats weird. Can you show your development.rb and Gemfile ? – Simon Franzen Mar 06 '18 at 23:06

0 Answers0