Custom initializers seems to not work good with rails console

Open
#552 2 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rails, ruby

Research direction

Reproduce the behavior using the custom /lib/my_module.rb, /config/initializers/my_module.rb, and rails c described in the issue, comparing a fresh initializer edit with later console starts. Trace how Spring and the Rails console load or reuse the initializer, and consider the issue resolved when MyModule.some_attr consistently reports 'some_val' without requiring an immediate initializer edit.

Written by the indexing model from the issue text.

Description

bug

Hey Guys, I've recently posted a question on SO, but no one answers, I think that my issue is actually related to spring, here's the question:
https://stackoverflow.com/questions/48461291/ruby-on-rails-5-2-0-beta2-initializers-loading
Long story short: I have a custom (not from any gem) module in /lib/my_module.rb inside a rails (5.2.0.beta2) project, like this:

module MyModule
  mattr_accessor :some_attr
  self.some_attr = nil

  # Default way to setup MyModule.
  def self.setup
    yield self
  end
end

And I have an initializer for it, /config/initializers/my_module.rb:

MyModule.setup do |config|
  config.some_attr = 'some_val'
end

But when I run rails c I have MyModule.some_attr set to nil always, and only if I change something in MyModule initializer and nothing else after it, and run rails c immediately I have MyModule.some_attr set to 'some_val'.

Dominant language
Ruby
Stars
2.8k
Forks
342
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rails/spring

All issues in rails/spring

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.