Rails服务器错误:未定义的方法' active_record'

时间:2015-07-11 12:56:48

标签: ruby-on-rails ruby ruby-on-rails-4

我是一个Rails 4初学者,他整夜都在试图启动我的rails服务器。我正在通过Hartls' Ruby on Rails教程第3版Rails 4.我已经能够完成一个\#34; hello world"样式应用程序并在我的本地服务器上运行它。哎呀,我甚至在第2章设置了toy_app,允许一些用户输入和微博。

突然间,情况发生了变化,我陷入了困境。我无法在我创建的任何新应用上运行rails服务器。这就是我的意思:

首先,我运行相同的命令在我的工作区中设置应用程序:

cd
cd workspace
rails _4.2.2_ new sample_app  

这将返回与之前两个成功的应用程序相同的基本Rails结构。现在,我打开gem文件,然后编辑gem文件,使其看起来像Hartl为第3章练习列出的那个。

这是Gem文件:

source 'https://rubygems.org'

gem 'rails',                '4.2.2'
gem 'sass-rails',           '5.0.2'
gem 'uglifier',             '2.5.3'
gem 'coffee-rails',         '4.1.0'
gem 'jquery-rails',         '4.0.3'
gem 'turbolinks',           '2.3.0'
gem 'jbuilder',             '2.2.3'
gem 'sdoc',                 '0.4.0', group: :doc

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
end

接下来,我运行了bundle_install,这就是我从终端返回的内容(我在Mac上):

Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.7.0
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.2
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile 0.6.2
Using nokogiri 1.6.6.2
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.6
Using loofah 2.0.2
Using rails-html-sanitizer 1.0.2
Using actionview 4.2.2
Using rack 1.6.4
Using rack-test 0.6.3
Using actionpack 4.2.2
Using globalid 0.3.5
Using activejob 4.2.2
Using mime-types 2.6.1
Using mail 2.6.3
Using actionmailer 4.2.2
Using activemodel 4.2.2
Using arel 6.0.1
Using activerecord 4.2.2
Using debug_inspector 0.0.2
Using binding_of_caller 0.7.3.pre1 (was 0.7.2)
Using bundler 1.9.6
Using columnize 0.9.0
Using debugger-linecache 1.2.0
Using slop 3.6.0
Using byebug 3.4.0 (was 5.0.0)
Using coffee-script-source 1.9.1.1
Using execjs 2.5.2
Using coffee-script 2.4.1
Using thor 0.19.1
Using railties 4.2.2
Using coffee-rails 4.1.0
Using multi_json 1.11.2
Using jbuilder 2.2.3 (was 2.3.1)
Using jquery-rails 4.0.3 (was 4.0.4)
Using sprockets 3.2.0
Using sprockets-rails 2.3.2
Using rails 4.2.2
Using rdoc 4.2.0
Using sass 3.4.16
Using tilt 1.4.1
Using sass-rails 5.0.2 (was 5.0.3)
Using sdoc 0.4.0 (was 0.4.1) 
Using spring 1.1.3 (was 1.3.6)
Using sqlite3 1.3.9 (was 1.3.10)
Using turbolinks 2.3.0 (was 2.5.3)
Using uglifier 2.5.3 (was 2.7.1)
Using web-console 2.0.0.beta3 (was 2.2.1)
Bundle complete! 12 Gemfile dependencies, 56 gems now installed.
Gems in the group production were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

我注意到这一次终端没有提示我输入我的密码,我相信它在过去。我假设这个错误发生在捆绑器这里,但我不确定它是什么。是否与跳过生产组有关?我知道Hartl建议稍后为了heroku部署而跳过它,但我还没有在我的Gemfile中列出一个生产组!无论如何,接下来我打电话

cd ~/workspace/sample_app    
rails server

以下是我的回复:

Warning: Running `gem pristine --all` to regenerate your installed gemspecs     (and deleting then reinstalling your bundle if you use bundle --path) will improve   the startup performance of Spring. 
/Library/Ruby/Gems/2.0.0/gems/railties-   4.2.2/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `active_record' for #<Rails::Application::Configuration:0x007fd1dc4fb158>  (NoMethodError)
from /Users/SSSPro02/workspace/matt_app/config/application.rb:24:in   `<class:Application>'
from /Users/SSSPro02/workspace/matt_app/config/application.rb:10:in `<module:MattApp>'
from /Users/SSSPro02/workspace/matt_app/config/application.rb:9:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:78:in `require'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in `server'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.2/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/SSSPro02/workspace/matt_app/bin/rails:8:in `require'
from /Users/SSSPro02/workspace/matt_app/bin/rails:8:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load'
from /Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'
from /Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /Library/Ruby/Gems/2.0.0/gems/spring-1.1.3/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/SSSPro02/workspace/matt_app/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

从我收集到的信息来看,它告诉我它无法找到“active_record”,直到现在才出现这个问题。我甚至试图在第1章中使用不同的gem文件重新创建基本的hello_world应用程序,每当我尝试启动服务器时,我仍然会收到此错误。任何帮助将不胜感激。如果我有任何其他信息,请告诉我。

2 个答案:

答案 0 :(得分:0)

您是否尝试过手动从Rails应用程序中运行捆绑包?所以:

cd sample_app
bundle

答案 1 :(得分:0)

尝试bundle update

再次尝试删除Gemfile.lock,然后再删除bundle install

验证您的config/application.rb是否存在此行?

require "active_record/railtie" 如果没有添加它,如果是,则注释然后取消注释。

相关问题