Ruby - ActiveRecord::ConnectionNotEstablished

前端 未结 12 1709
臣服心动
臣服心动 2020-12-30 19:08

I am rather new to Ruby and have been following along with the book \"Ruby On Rails 3 Tutorial - Learn Ruby by Example - by Michael Hartl\". I am currently in Chapter 3 whic

相关标签:
12条回答
  • 2020-12-30 19:56

    In development environment, just run

    bundle exec rake db:setup
    

    In production environment, run

    bundle exec RAILS_ENV=production rake db:setup
    
    0 讨论(0)
  • 2020-12-30 19:59

    Below steps worked for me..

    1. create blank development.sqlite3 file in db/ folder.

    2. close current terminal and create fresh terminal

    Then run rails server

    0 讨论(0)
  • 2020-12-30 20:03
    bundle install
    bundle update
    rake db:setup
    rake db:migrate
    rake db:seed
    # remember to restart the server
    rails server
    
    0 讨论(0)
  • 2020-12-30 20:08

    Using the latest sqlite3 + bundle update + bundle install worked for me. I believe the restriction to an older sqlite3 version per the walkthrough is likely messing things up. Here's my gemfile:

    source 'https://rubygems.org'
    
    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '4.0.0'
    
    
    
    # Use sqlite3 as the database for Active Record
    gem 'sqlite3'
    
    
    # Use SCSS for stylesheets
    gem 'sass-rails', '~> 4.0.0'
    
    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 1.3.0'
    
    # Use CoffeeScript for .js.coffee assets and views
    gem 'coffee-rails', '~> 4.0.0'
    
    # See https://github.com/sstephenson/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby
    
    # Use jquery as the JavaScript library
    gem 'jquery-rails'
    
    # Turbolinks makes following links in your web application faster. Read more:     https://github.com/rails/turbolinks
    gem 'turbolinks'
    
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 1.2'
    
    group :doc do
      # bundle exec rake doc:rails generates the API under doc/api.
      gem 'sdoc', require: false
    end
    
    # Use ActiveModel has_secure_password
    # gem 'bcrypt-ruby', '~> 3.0.0'
    
    # Use unicorn as the app server
    # gem 'unicorn'
    
    # Use Capistrano for deployment
    # gem 'capistrano', group: :development
    
    # Use debugger
    # gem 'debugger', group: [:development, :test]
    
    0 讨论(0)
  • 2020-12-30 20:09

    Make sure that you have installed sqlite3 gem.

    If so did you run the following commands,

    rake db:create # to create database
    rake db:migrate # to create tables based on your migration
    

    If the above two works fine, your application should be able to connect to the database. Else please copy the trace application trace over here, that may help us to help you better.

    0 讨论(0)
  • 2020-12-30 20:11

    I was migrating from a previous version of Rails. For me the fix was to add

    require 'rails/all'

    at the top of application.rb instead of the 5 separate requires I had.

    0 讨论(0)
提交回复
热议问题