Mikone
Mikone

Reputation: 141

Production environment error

To begin, I'm quite a newbie to Rails. I'm making a blog app, and when trying to run it on production, both ways:

rails s -e production

and

RAILS_ENV=production

I get the same error:

=> Booting WEBrick => Rails 3.2.8 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/loku/.rvm/gems/ruby-1.9.3-p286/gems/activerecord-> resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
...

My setup:

ruby 1.9.3p286 (2012-10-12 revision 37165) [i686-linux]

Rails 3.2.8

database.yml:

development:    
  adapter: mysql2    
  encoding: utf8    
  reconnect: false    
  database: blogg_development    
  pool: 5    
  timeout: 5000    
  username: root    
  password: *** 
  host: localhost    

production:    
  adapter: mysql2       
  encoding: utf8    
  reconnect: false    
  database: blogg_production    
  pool: 5    
  timeout: 5000    
  username: root    
  password: ***    
  host: localhost

Gemfile:

source 'https://rubygems.org'
ruby '1.9.3'
gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
  gem 'haml-rails'
  gem 'less-rails'
  gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-    rails.git'
  #gem 'actionpack', '~> 3.1.0'
end

gem 'jquery-rails'
gem 'haml'
gem 'devise'
gem 'cancan'

group :test, :development do
  gem 'guard-livereload'
  gem 'rb-fsevent'
  gem 'pry'
  gem 'pry-rails'
end

group :linux do
  gem 'libnotify'
end

group :darwin do
  gem 'rb-fsevent', require: false
  gem 'growl'
end

Upvotes: 14

Views: 914

Answers (6)

Joe Saunders
Joe Saunders

Reputation: 798

You might need to add a production group in your gemfile... Something like the following:

group :production do
    gem 'mysql2'
end

The run bundle install from the terminal and trying starting it all again.

Upvotes: 1

Uri Mikhli
Uri Mikhli

Reputation: 681

  1. Your Gemfile needs to specify the mysql gem. -- never mind I see that it does now.
  2. You need to specify the db socket. Its not always in /tmp/mysql.sock sometimes its in /var... it depends on your install of mysql2

    socket: /tmp/mysql.sock needs to be a line in your database.yml production section

e.g.

production:    
  adapter: mysql2       
  encoding: utf8    
  reconnect: false    
  database: blogg_production    
  pool: 5    
  timeout: 5000    
  username: root    
  password: ***
  socket: /tmp/mysql.sock    
  host: localhost
  1. yml is funny about indenting. Double check that it's correct.

Upvotes: 1

janfoeh
janfoeh

Reputation: 10328

Please make doubly certain what Rumen Milushev suggested: YAML is very sensitive to indentation.

Try removing the production: part completely, rename development: to production: and try again.

If that works, validate your database.yml against a tool such as yamllint.com

Upvotes: 1

Gjaldon
Gjaldon

Reputation: 5644

Basing on the source, there are only 2 possible explanations for the error you got. AdapterNotSpecified - Raised when adapter not specified on connection (or configuration file config/database.yml misses adapter field).

Did you copy and paste your database.yml file? If so, you might want to erase it and type them all again from scratch. Make sure indentation is consistent. Sometimes when copy and pasting, you also copy some hidden characters which get evaluated and cause problems in your code.

Hope that helps.

Upvotes: 2

lsaffie
lsaffie

Reputation: 1814

These are the things to consider

  1. mysql2 in Gemfile (it is)
  2. production environment defined in config/database.yml (it is) 2.2 remove any other environments from your database.yml and leave production: only
  3. Make sure it's properly indented (I think it is)
  4. bundle install (to make sure you have the gems installed)
  5. bundle show mysql2 to see the version and ensure it's installed
  6. bundle exec rails s -e production (make sure to use bundle exec)

  7. if that doesn't work, I would look in config/environments/production.rb and ensure there isn't anything rare there.

Upvotes: 4

pkurek
pkurek

Reputation: 606

You need to specify all environments you forgot about test thats probably why the error is happening

Upvotes: -2

Related Questions