2015-07-11 55 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" 如果沒有添加它,如果是和評論然後取消註釋它。

相關問題