2015-07-11 66 views
1

我是一个Rails 4的初学者,一直坚持尝试启动我的Rails服务器。我正在通过Hartls的Ruby on Rails教程第三版Rails 4开展工作。我已经能够完成“Hello world”风格的应用程序,并在本地服务器上运行它。嘿,我甚至在第2章中设置了toy_app,允许用户输入和微博。Rails的服务器错误:未定义的方法'active_record'

突然,事情发生了变化,我被卡住了。我无法在我创建的任何新应用程序上运行rails服务器。这就是我的意思是:

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

cd 
cd workspace 
rails _4.2.2_ new sample_app 

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

这里是宝石文件:

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应用程序,并且每当我尝试启动服务器时仍会收到此错误。任何帮助将不胜感激。如果有任何其他信息,请告诉我。

+0

您使用的是类似rvm还是rbenv? –

回答

0

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

cd sample_app 
bundle 
+0

谢谢你的回应,丹。尽管有同样的警告。 – mthrasher33

0

尝试bundle update

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

确认您的config/application.rb是这条线吗?

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

相关问题