我正在学习Rails教程第3章。
我无法执行以下命令。如果你有想法解决这个问题,请告诉我。
感谢。
exec命令
bundle exec rails generate rspec:install
错误
/Users/mofuty/rails_projects/sample_app/config/application.rb:5:in `require': cannot load such file -- active_job/railtie (LoadError)
from /Users/mofuty/rails_projects/sample_app/config/application.rb:5:in `<top (required)>'
from /Users/mofuty/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.0.5/lib/rails/commands.rb:43:in `require'
from /Users/mofuty/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.0.5/lib/rails/commands.rb:43:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'
的Gemfile
source 'https://rubygems.org'
ruby '2.1.2'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.5'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.5'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
以下是apprication.rb。如果您需要更多详细信息,请询问我。
配置/ application.rb中
require File.expand_path('../boot', __FILE__)
# 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 the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production. Bundler.require(*Rails.groups)
module SampleApp 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
答案 0 :(得分:0)
尝试bundle exec rails generate rspec:install
bundle exec
是一个Bundler命令,用于在当前包的上下文中执行脚本(来自目录的Gemfile)
答案 1 :(得分:0)
听起来好像你的测试套件正在调用一些依赖于Rails 4中新ActiveJob framework的代码。
该错误表明您的config/application.rb
文件中未包含铁路。如果您打开它,您可能会发现它已被注释掉,请查找如下所示的行:# require "active_job/railtie"
如果是,请取消注释。如果该行未包含在该文件中,请在require "active_job/railtie"
后的新行中添加require "active_model/railtie"
。
这将确保在Rails初始化时加载活动作业栏。
答案 2 :(得分:0)
感谢您的建议。问题是我使用rails 4.2.x执行rails new
。所以,我用4.0.5重建了这个项目。然后我可以执行bundle exec rails generate rspec:install
。我很感激你。