Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `preload' for RailsConfig::Integration::Rails::Railtie:Class (NoMethodError) #111

Closed
navaneeth opened this issue Jul 22, 2015 · 10 comments
Labels
Milestone

Comments

@navaneeth
Copy link

I am trying to load rails_cofig before rails loads. Followed the instructions give in the README. Here is my application.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'
require 'rails_config'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
RailsConfig::Integration::Rails::Railtie.preload

module Api
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Do not swallow errors in after_commit/after_rollback callbacks.
    config.active_record.raise_in_transactional_callbacks = true
  end
end

But this fails with error

undefined method `preload' for RailsConfig::Integration::Rails::Railtie:Class (NoMethodError)

Rails version - Rails 4.2.3
Ruby version - ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]

@j2d3
Copy link

j2d3 commented Aug 4, 2015

I'm having the same problem with the same version of Rails and Ruby

@fredwu
Copy link
Member

fredwu commented Aug 6, 2015

The two lines below need to be executed in your Application class according to the README, right? You had them executed before outside of the class.

Bundler.require(*Rails.groups)
RailsConfig::Integration::Rails::Railtie.preload

@pkuczynski
Copy link
Member

Instead of loading Config before loading Rails, could you describe your usage scenario? I have already made Config available on the earlier Rails loading stages (like to be able to use it in database.yml), so maybe your scenario is general enough that we can provide a general solution for this?

@RoLoTo
Copy link

RoLoTo commented Aug 28, 2015

Move the two lines into your Application class block in application.rb. I found I had to change "RailsConfig" to "Config" to get it to tie in. So:

Bundler.require(*Rails.groups)
RailsConfig::Integration::Rails::Railtie.preload

becomes:

Bundler.require(*Rails.groups)
Config::Integration::Rails::Railtie.preload

@YaroSpace
Copy link

I am having the same problem. Not sure if this is a correct way to go, but moving the line config.before_configuration { preload } after the preload method definition in the config/integration/rails.rb worked for me.

@giorgian
Copy link

giorgian commented Mar 1, 2016

My scenario: config used in a Rails engine initialiser.

Everything works fine in the Rails app, but rake test inside the engine fails. YaroSpace's fix solves the problem.

P.S. are there special guidelines on how to use config in an engine?

@YaroSpace
Copy link

I am also using it in the engine and also in the wrapper apps.
This is how I do it:

  1. I require config in the wrapper app (by including into Gemfile). This way the gem gets initialized and the app specific config is picked up.
  2. In the engine, I have a custom initializer, which reads engine specific config and prepends it to Settings. (Settings.prepend_source!(..); Settings.reload!). So, the engine config settings are picked up, when the engine is initialized.

This assumes that config gem must be required before the engine gem, or just include defined?(Settings) in the engine initializer.

@giorgian
Copy link

giorgian commented Mar 1, 2016

Thanks, I'll experiment with that, although in my case I don't foresee using engine specific configuration, just the wrapper ones (and of course the test/dummy ones).

@pkuczynski pkuczynski added this to the 1.3 milestone May 12, 2016
@pkuczynski
Copy link
Member

I updated the rails integration code like @YaroSpace suggests and pushed to the repo (no new gem release yet, so you would have to test it referencing github repo).

The description in README about manually loading preload should not be valid anymore IMHO, as the config should load by default before Rails application configuration. See #145

If someone could test and confirm, it would be awesome!

pkuczynski pushed a commit that referenced this issue Jun 1, 2016
… undefined method `preload` error (based on @YaroSpace suggestion in #111)
@pkuczynski pkuczynski added the bug label Jun 1, 2016
Dev-Crea added a commit to Dev-Crea/dinin that referenced this issue Mar 19, 2017
@pkuczynski pkuczynski modified the milestones: 1.4, 1.6.0 Oct 23, 2017
@pkuczynski pkuczynski modified the milestones: 1.6.0, 1.6.1, 1.6.2 Nov 3, 2017
@pkuczynski pkuczynski modified the milestones: 1.7.0, 1.7.1 Feb 9, 2018
@pkuczynski pkuczynski removed this from the 1.7.1 milestone Jun 19, 2019
@pkuczynski
Copy link
Member

This seems to be fixed now. Please comment if you feel it is still not working properly.

@pkuczynski pkuczynski added this to the 2.0.1 milestone Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

7 participants