我一直试图解决这个问题近3个小时,但没有成功。当我尝试从第3章的教程中运行rails generate rspec:install
时,我得到了这个输出:
/home/patrick/rails_projects/sample_app/config/application.rb:30:in `': undefined local variable or method `config' for main:Object (NameError) from /home/patrick/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0.rc2/lib/rails/commands.rb:46:in `require' from /home/patrick/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0.rc2/lib/rails/commands.rb:46:in `' from bin/rails:4:in `require' from bin/rails:4:in `'
application.rb中:
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/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(:default, Rails.env)
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
end
end
config.generators do |g|
g.test_framework :rspec
end
patrick@X67895:~/rails_projects/sample_app$ gem list
*** LOCAL GEMS ***
actionmailer (4.0.0.rc2, 4.0.0.rc1, 3.2.13)
actionpack (4.0.0.rc2, 4.0.0.rc1, 3.2.13)
activemodel (4.0.0.rc2, 4.0.0.rc1, 3.2.13)
activerecord (4.0.0.rc2, 4.0.0.rc1, 3.2.13)
activerecord-deprecated_finders (1.0.3)
activeresource (3.2.13)
activesupport (4.0.0.rc2, 4.0.0.rc1, 3.2.13)
arel (4.0.0, 3.0.2)
atomic (1.1.9)
builder (3.1.4, 3.0.4)
bundler (1.3.5)
bundler-unload (1.0.1)
capistrano (2.15.4)
coffee-rails (4.0.0, 3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.2)
diff-lcs (1.2.4)
erubis (2.7.0)
execjs (1.4.0)
highline (1.6.19)
hike (1.2.3)
i18n (0.6.4, 0.6.1)
jbuilder (1.4.2, 1.0.2)
journey (1.0.4)
jquery-rails (3.0.1, 2.2.1)
json (1.8.0)
mail (2.5.4)
mime-types (1.23)
minitest (4.7.4)
multi_json (1.7.7)
net-scp (1.1.1)
net-sftp (2.1.2)
net-ssh (2.6.7)
net-ssh-gateway (1.2.0)
pg (0.15.1)
polyglot (0.3.3)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (4.0.0.rc2, 4.0.0.rc1, 3.2.13)
railties (4.0.0.rc2, 4.0.0.rc1, 3.2.13)
rake (10.0.4)
rdoc (3.12.2)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
rspec-mocks (2.13.1)
rspec-rails (2.13.2)
rubygems-bundler (1.2.0)
rvm (1.11.3.8)
sass (3.2.9)
sass-rails (4.0.0.rc2, 3.2.6)
sdoc (0.3.20)
sprockets (2.10.0, 2.2.2)
sprockets-rails (2.0.0)
sqlite3 (1.3.7)
thor (0.18.1)
thread_safe (0.1.0)
tilt (1.4.1)
treetop (1.4.14)
turbolinks (1.2.0, 1.1.1)
tzinfo (0.3.37)
uglifier (2.1.1)
我完全不知道下一步该做什么。
答案 0 :(得分:3)
在类中移动您的配置,如下所示:
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
config.generators do |g|
g.test_framework :rspec
end
end
end