简体   繁体   中英

rails tutorial - activerecord:connectionnotestablished error - after running rails S

I'm a Ruby on Rails Amateur currently learning from Michael Hartl's RailsTutorials.

I followed instructions on Ror tutorial , and after Listing 3.5, I didn't get the expected outcome.

After running Rails S, there is no home page or contact page shown at the given URL, and this was the error shone on the Web Browser.

ActiveRecord::ConnectionNotEstablished
Rails.root: /Users/username/rails_projects/sample_app

Anyone can help?

I ran into exactly the same problem when going through the (otherwise brilliant) tutorial.

What helped me was commenting out a line in config/application.rb . Here is what rails generates when running rails new sample_app -T on my system:

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
...

After doing some research on the internet I found this , which helped a lot. So here is what I did:

I commented out the line require "active_record/railtie" , removed the comment from the line require "rails/test_unit/railtie" and added another line like so:

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"

# For errors like ActiveRecord::RecordNotFound
require "active_record"

Now everything works just fine.

NB: I'm just a Rails rookie myself who ran into this exact problem, so you should take this answer with a grain of salt ...

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