升级ruby 1.8.7到1.9.3加载错误

时间:2015-12-03 17:21:38

标签: ruby-on-rails ruby ruby-1.9.3

尝试升级到ruby 1.9.3“小步骤”时出现加载错误。有一个加载错误,但我正在自动加载lib目录。有谁知道为什么会这样?

application.rb中:

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

require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)

module MyApp
  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.

    # Custom directories with classes and modules you want to be autoloadable.
    config.autoload_paths += %W(#{config.root}/extras #{config.root}/lib)

    # Only load the plugins named here, in the order given (default is alphabetical).
    # :all can be used as a placeholder for all plugins not explicitly named.
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

    # Activate observers that should always be running.
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

    # 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

    # JavaScript files you want as :defaults (application.js is always included).
    config.action_view.javascript_expansions[:defaults] = %w(delayed-observer jquery.rails)

    # Configure the default encoding used in templates for Ruby 1.9.
    config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password, :cc, :account_token]
  end
end
require 'lib/my-app/my-app'

console:

/Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require': cannot load such file -- lib/my-app/my-app (LoadError)
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `block in require'
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
    from /Users/jay/current_projects/my-app/config/application.rb:42:in `<top (required)>'
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
    from /Users/jay/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

1 个答案:

答案 0 :(得分:2)

Ruby 1.9更改了默认加载路径,因此通常需要将其替换为:

require_relative '../lib/my-app/my-app'

这样,您可以准确指定它的位置,而无需更改$LOAD_PATH配置。