简体   繁体   中英

Rails Server Error: Undefined Method 'active_record'

I'm a Rails 4 beginner who's been up all night stuck trying to start up my rails server. I'm working through Hartls' Ruby on Rails tutorial 3rd edition for Rails 4. I've been able to complete a \\ "hello world" style app and run it on my local server. Heck, I even set up the toy_app in chapter 2 that allowed some user input and microblogging.

Suddenly, things have changed, and I'm stuck. I can't run rails server on any new apps I create. Here's what I mean:

First, I run the same commands to set up an app in my workspace:

cd
cd workspace
rails _4.2.2_ new sample_app  

This returns the same basic Rails structure as my two previously successful apps. Now, I open the gem file, and I edit the gem file to look like the one Hartl has listed for the Chapter 3 exercise.

Here is the Gem file:

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

Next, I run bundle_install, and this is what I get back from the terminal (I'm on a 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.

I notice this time around that the terminal does not prompt me for my password, which I believe it had in the past. I'm assuming that the error is happening here with the bundler, but I'm not sure what it is. Does it have to do with skipping the production group? I know Hartl recommends skipping it later for the sake of heroku deployment, but I don't even have a production group listed in my Gemfile yet! Anyway, next I call

cd ~/workspace/sample_app    
rails server

And here is what I get back:

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>'

From what I gather, it's telling me it can't find 'active_record', which has not been a problem until now. I've even tried to recreate the basic hello_world app in chapter 1 with a different gem file, and I am still getting this error whenever I try to start up the server. Any help would be greatly appreciated. Let me know if there is any additional information I should include.

Have you tried running bundle from inside your Rails app manually? So:

cd sample_app
bundle

Try bundle update .

Try delete Gemfile.lock then bundle install again.

Verify your config/application.rb is this line present?

require "active_record/railtie" if not add it, if yes and commented then uncomment it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM