铁路无法加载此类文件

时间:2016-01-10 04:12:09

标签: ruby-on-rails ruby

首先,你应该事先知道我是铁杆的新手,所以如果这是一个愚蠢的错误,我道歉,但我一直在绞尽脑汁,并认为我会寻求帮助。

我目前无法突然启动本地rails服务器。不知道我做了什么导致这一点因为我能够在今天早些时候开始它就好了。我在工作与否之间所做的只是试图弄清楚如何将应用推向Heroku。

在应用根目录中运行rails s时出现此错误:

/Users/jonathanmacdonald/code/lrbp/config/application.rb:6:in `require':     cannot load such file -- active_job/railtie (LoadError)
    from /Users/jonathanmacdonald/code/lrbp/config/application.rb:6:in     `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/railties-    4.2.3/lib/rails/commands/commands_tasks.rb:78:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/railties-    4.2.3/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    from /Library/Ruby/Gems/2.0.0/gems/railties-    4.2.3/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /Library/Ruby/Gems/2.0.0/gems/railties-    4.2.3/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /Library/Ruby/Gems/2.0.0/gems/railties-    4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Library/Ruby/Gems/2.0.0/gems/railties-    4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/jonathanmacdonald/code/lrbp/bin/rails:10:in `require'
    from /Users/jonathanmacdonald/code/lrbp/bin/rails:10:in `<top     (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/spring-    1.6.2/lib/spring/client/rails.rb:28:in `load'
    from /Library/Ruby/Gems/2.0.0/gems/spring-    1.6.2/lib/spring/client/rails.rb:28:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/spring-    1.6.2/lib/spring/client/command.rb:7:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/spring-    1.6.2/lib/spring/client.rb:28:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/spring-1.6.2/bin/spring:49:in `<top     (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/spring-    1.6.2/lib/spring/binstub.rb:11:in `load'
    from /Library/Ruby/Gems/2.0.0/gems/spring-    1.6.2/lib/spring/binstub.rb:11:in `<top (required)>'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in     `require'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in     `require'
    from /Users/jonathanmacdonald/code/lrbp/bin/spring:13:in `<top     (required)>'
    from bin/rails:4:in `load'
    from bin/rails:4:in `<main>'

的Gemfile

source 'https://rubygems.org'

group :production do
  gem 'rails', '4.2.3'
  gem 'pg'
  gem 'rails_12factor'
  gem 'bootstrap-sass'
end

group :development, :test do
  gem 'sqlite3'
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'binding_of_caller'
  gem 'better_errors'
end

配置/ application.rb中

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

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
require 'rails/all'

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

module Lrbp
  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
    config.assets.initialize_on_precompile = false
  end
end

我在研究后尝试过的事情

  • bundle exec rails server - &gt;&gt;仍然不会开始并产生完全相同的错误
  • 暂时mv Gemfile.lock ..以便我可以使用bundle install - &gt;&gt;重新生成它没变。同样的错误。
  • gem pristine --all - &gt;&gt;没变。同样的错误。
  • gem uninstall rails然后gem install rails - &gt;&gt;没变。同样的错误。

设置

  • OS X 10.11.2
  • Rails 4.2.3
  • Ruby 2.0.0

我可以寻找或尝试什么?任何帮助表示赞赏。如果您需要更多信息以便提供帮助,请与我们联系。

1 个答案:

答案 0 :(得分:0)

您的application.rb看起来像

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

require 'rails/all'

Bundler.require(:default, Rails.env)

module Lrbp
  class Application < Rails::Application

您不需要像

那样单独使用每个导轨模块
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"

你可以使用。

  require 'rails/all'

它会做这样的事情

%w(
  active_record
  action_controller
  action_view
  action_mailer
  rails/test_unit
  sprockets
).each do |framework|
  begin
    require "#{framework}/railtie"
  rescue LoadError
  end
end

和Gemfile

source 'https://rubygems.org'

  gem 'rails', '4.2.3'
  gem 'pg'
  gem 'rails_12factor'
  gem 'bootstrap-sass'

group :development, :test do
  gem 'sqlite3'
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
  gem 'binding_of_caller'
  gem 'better_errors'
end

然后你应该做

bundle install & bundle exec rails s