I'm trying to install PostgreSQL on my Ruby app, and am running into a problem. Whenever I'm trying to start my server I get an error stating:
rescue in spec': Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
which is weird because I've already added it to my Gemfile and ran bundle install and ran bundle list to check if it's been installed (which it is).
To run you through to what I've done.
I've started my PostgreSQL database, created a database and gave it a name & password.
Then I've changed the database.yml to:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
encoding: unicode
pool: 5
# Important configs for cloud9, change password value
# to what you entered in the previous psql step.
template: template0 (not sure what the fill in here?)
username: my_username (can be omitted)
password: my_password (can be omitted)
development:
<<: *default
database: my_database_development
test:
<<: *default
database: my_database_test
production:
<<: *default
database: my_database_production
username: my_username
password: <%= ENV['my_password'] %>
Then I added gem 'pg' to my gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/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', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'rake'
gem 'rspec'
gem 'kramdown'
gem 'thor', '0.19.1'
gem 'spree_braintree_vzero', github: 'spree-contrib/spree_braintree_vzero'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'capistrano-passenger'
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'pg'
end
group :development do
gem 'pg'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
gem 'spree', '~> 3.1.0.rc1'
gem 'spree_auth_devise', '~> 3.1.0.rc1'
gem 'spree_gateway', '~> 3.1.0.rc1'
gem 'devise'
gem 'materialize-sass'
gem 'active_link_to'
gem 'mollie-api-ruby'
# gem 'spree_mollie', github: 'salman15/mollie_spree_2017', branch: 'stable'
gem 'spree_mollie', github: 'ttcremers/spree_mollie', branch: 'stable'
group :production do
gem 'pg'
end
Then I try to start my server and get the following error:
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
EDIT (10:12pm 31-01-18 CET)
I'm running the app on Cloud9 (which is ubuntu), previous/current database is SQlite (Default), but now that I want to deploy the website it needs to be changed to a better database. Therefore PostgreSQL, current pg version is 1.0
bundle show pgand do you see the gem listed?gem 'pg', '~> 0.21'to gemfile and bundle?