Ruby on rails $ mysql configuration - ruby-on-rails

I want to configure mysql instead of Sqlite3. I had already configured the database.yml file:
development:
adapter: mysql
database: test
username:false
password:neha
host :localhost
port:3306
and also installed the mysql gem using gem install mysql
still i stuck out in error...please help me out
:\rails\TestApp1>ruby script/server
Booting WEBrick
Rails 2.3.11 application starting on http://0.0.0.0:3000
:/Ruby192/lib/ruby/1.9.1/syck.rb:135:in load': syntax error on line 13, col 0:test:' (ArgumentError)
from C:/Ruby192/lib/ruby/1.9.1/syck.rb:135:in load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:926:indatabase_configuration'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:437:in initialize_database'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:141:inprocess'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/initializer.rb:113:in run'
from C:/rails/TestApp1/config/environment.rb:9:in'
from :29:in require'
from <internal:lib/rubygems/custom_require>:29:inrequire'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in block in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:547:innew_constants_in'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.11/lib/commands/server.rb:84:in'
from :29:in require'
from <internal:lib/rubygems/custom_require>:29:inrequire'
from script/server:3:in `'
i got this error
#d11wtq:
here is my yml file for mysql configuration:
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "neha",
:database => "ruby"
)
& where i have to put
require 'mysql'

Looking at that log output you've now posted, it looks like you have haven't formatted that .yml file correctly. The use of whitespace in YAML is absolutely critical. Indent with spaces, not tabs, and make sure your indentation is consistent within each level. It appears that the lines are all aligned differently in your file, which is causing syck (the YAML parser) to throw an Exception.
EDIT | You also want to make the spacing between the key, the semi-colon and the value consistent too. Take pride in the layout of your code and you'll enjoy coding more ;) But pride or not... YAML is (intentionally) picky about whitespace.

Have your yml files properly indented and you will not be getting syntax error anymore.
Also add mysql2 compatible version in your Gemfile, so that while you will be deploying it to any server it will take from Gemfile automatically.

Did you add "mysql" to your Gemfile and run "bundle install"?

If you're working on Windows, I know that I didn't have the MySQL C Driver installed on my machine. It's a different download than the MySQL Community Server. You also have to make sure that your PATH has the route to the C driver. Download the driver here.

Related

Mongoid::Errors::NoSessionConfig in rails consolse

I clone rails app (our company project) and then install everything that related to mongo db and mongoid gem. Then I run the rake db:setup and then rails s. Its working fine, I can access all the sites and do everything. But I got problem in the rails console.
Whenever I do this:
rails c
then
User.first
I will get this error
Loading development environment (Rails 4.1.1) irb(main):001:0>
User.first Mongoid::Errors::NoSessionConfig: Problem: No
configuration could be found for a session named 'default'. Summary:
When attempting to create the new session, Mongoid could not find a
session configuration for the name: 'default'. This is necessary in
order to know the host, port, and options needed to connect.
Resolution: Double check your mongoid.yml to make sure under the
sessions key that a configuration exists for 'default'. If you have
set the configuration programatically, ensure that 'default' exists in
the configuration hash. from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions/factory.rb:27:in
create' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions.rb:65:in
with_name' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions.rb:105:in
mongo_session' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions.rb:121:in
collection' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/sessions/options.rb:161:in
method_missing' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual/mongo.rb:263:in
initialize' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual.rb:53:in
new' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual.rb:53:in
create_context' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual.rb:35:in
context' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/contextual.rb:20:in
first' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mongoid-4.0.0.beta2/lib/mongoid/findable.rb:122:in
first' from (irb):1 from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in
start' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in
start' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in
console' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in
run_command!' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in
' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in require' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inblock in require' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in load_dependency' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inrequire' from
/Users/rizalmuthi/Documents/Sites/WORK/tapway/bin/rails:8:in <top
(required)>' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:inload' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in block in load' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:inload_dependency' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in load' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in
require' from
/Users/rizalmuthi/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in
require' from -e:1:in'irb(main):002:0>
And FYI, this is the mongoid.yml that I generated by run
rails g mongoid:config
mongoid.yml
development:
sessions:
default:
database: mongo_demo_development
hosts:
- localhost:27017
options:
options:
test:
sessions:
default:
database: mongo_demo_test
hosts:
- localhost:27017
options:
consistency: :strong
max_retries: 1
retry_interval: 0
I have been looking all over google and some blogs, could not figure it out how to fix this.
Besides that, we dont use the Rspec tho.
change your config/application.rb file:
replace it Bundler.require(*Rails.groups)
to it Bundler.require(*Rails.groups(assets: %w(development test)))
In the latest mongoid -5.0.0 version you can simply solve by placing the below code in application.rb
config.generators do |g|
g.orm :mongoid
end
In config/application.rb change
Bundler.require(*Rails.groups)
to:
Bundler.require(:default, Rails.env)
Rails is trying to eager load the group of gems by environment and the stock config/mongoid.yml file you get when you run rails g mongoid:config only gives you a test and development namespace. Even though you're only running development, it's looking at all the groups. If you add the production namespace to the yml file it will load but my answer above works without you needing to do that.
Just make sure that on application initialization you do the following (in Rails console)
Mongoid.load!("path/to/your/mongoid.yml")
For more details visit http://mongoid.org/en/mongoid/docs/installation.html
With MongoId version 5.x, You will change config in Rails application follow:
File: application.rb
# Add line.
config.generators do |g|
g.orm :mongoid
end
I was set it and it working in rails console.
See more at:
https://docs.mongodb.com/ecosystem/tutorial/mongoid-installation/#rails-applications
may be The problem is in the gem file, you did't mention the version of mongoid gem.
in gem file change
gem "mongoid"
to
gem "mongoid" , '~> 4.0.2'
and run bundle install
restart server and console.

ArgumentError: odd number of arguments for Hash when trying to connect to redis

I'm trying to get rails connect to redis by following this tutorial.
But I'm getting the following error when I try $redis = Redis.new(:host => 'localhost', :port => 6379) or even just Redis.new. I've tried the new notation as well (host: 'localhost',port: 6379). Redis works (ping-PONG test via redis-cli passes).
ArgumentError: odd number of arguments for Hash
from /var/lib/gems/1.9.1/gems/redis-2.1.1/lib/redis.rb:65:in `[]'
from /var/lib/gems/1.9.1/gems/redis-2.1.1/lib/redis.rb:65:in `info'
from /var/lib/gems/1.9.1/gems/redis-2.1.1/lib/redis.rb:606:in `inspect'
from /var/lib/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /var/lib/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /var/lib/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
What am I doing wrong?
Config Details:
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ rails -v
Rails 4.0.0
I receive the same error using the redis gem version 2.1.1. Try to update the redis gem to latest, which is version 3.0.4.
To update the redis gem, you can either run
gem update redis
to update the locally installed version, or run
bundle update redis
to update the redis gem that is installed as part of your Gemfile.
$ irb
1.9.3p392 :001 > require 'redis'
=> true
1.9.3p392 :002 > Redis.new(:host => 'localhost', :port => 6379)
ArgumentError: odd number of arguments for Hash
from /Users/zachallett/.rvm/gems/ruby-1.9.3-p392/gems/redis-2.1.1/lib/redis.rb:65:in `[]'
from /Users/zachallett/.rvm/gems/ruby-1.9.3-p392/gems/redis-2.1.1/lib/redis.rb:65:in `info'
from /Users/zachallett/.rvm/gems/ruby-1.9.3-p392/gems/redis-2.1.1/lib/redis.rb:606:in `inspect'
from /Users/zachallett/.rvm/rubies/ruby-1.9.3-p392/bin/irb:16:in `<main>'
.
$ irb
1.9.3p392 :001 > require 'redis'
=> true
1.9.3p392 :002 > Redis.new(:host => 'localhost', :port => 6379)
=> #<Redis client v3.0.4 for redis://localhost:6379/0>
Had the following issue but we couldn't upgrade the redis gem to 3.x. It turned out that redis-rb was looking for a key/value pair for the redis config which didn't exist when running redis-server.
Running redis-server with the config file
redis-server /usr/local/etc/redis.conf
fixed the issue.
I haven't used redis yet, but based on a cursory look, seems like you're using the redis-ruby library. You probably want to experiment with redis-rails when it's available!(http://rubygems.org/gems/redis-rails)
The easiest way out is, look for Gemfile, and remove information about the redis gem. Replace that line with:
gem 'redis-rails'
Save the file, then run:
$ bundle install
I had the very same issue, turns out homebrew had updated my redis-server from 2.6.x to 2.8.6
I reverted back to an older version of redis and it worked!
I've ran into the same error. The first thing I notices is that this error is related to the visual output that gets displayed in the console as a representation of the object. The inspect method is what gets called for this purpose. See the following from the stack trace:
/var/lib/gems/1.9.1/gems/redis-2.1.1/lib/redis.rb:606:in 'inspect'
So if you do redis = Redis.new(:host => 'localhost', :port => 6379)
or anytime you type just redis therafter, you'll get this error. However if you ignore it and just do
redis.get 'foo' everything works just fine.

Faye setup in production

I've set up Faye on localhost, and works fine.
I'm now trying to deploy it on DigitalOcean VPS, with Cloud66 deployment service.
To run the command I use an "after_rails" hook.
rackup $RAILS_STACK_PATH/faye.ru -s thin -E production
This gives me the error:
Error during deployment: Error during after_rails hook: Server: not_specified. Failed to run command: /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- faye (LoadError) from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire' from /var/deploy/anabol/web_head/current/faye.ru:1:in block in <main>' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:ininstance_eval' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in initialize' from /var/deploy/anabol/web_head/current/faye.ru:innew' from /var/deploy/anabol/web_head/current/faye.ru:in <main>' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:49:ineval' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in new_from_string' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:40:inparse_file' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:277:in build_app_and_options_from_config' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:199:inapp' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:314:in wrapped_app' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:250:instart' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:141:in start' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.5.2/bin/rackup:4:in' from /usr/local/bin/rackup:23:in load' from /usr/local/bin/rackup:23:in'
github repo:
https://github.com/gwuix2/anabol
Any suggestions what could be the problem? Don't know where to start.
I've written up some documentation on how to solve this problem in case anyone else runs into it. You can find it here: http://community.cloud66.com/articles/faye-on-cloud-66
Disclaimer: I work for Cloud 66.
Cloud 66 Support solved my problem:
Hi there,
We run faye on our own stack. We actually run it behind thin - and monitor it as a process on the stack. The way we do this is with four files - see their details below:
1) RAILS_ROOT/.cloud66/deploy_hooks.yml
production:
before_rails:
- source: /.cloud66/files/add_thin_and_faye.sh
destination: ~/add_thin_and_faye.sh
target: rails
execute: true
sudo: true
apply_during: build_only
run_on: all_servers
2) RAILS_ROOT/.cloud66/files/add_thin_and_faye.sh
#!/bin/bash
sudo gem install thin --no-ri --no-rdoc
sudo gem install faye --no-ri --no-rdoc
3) RAILS_ROOT/Procfile
faye: thin -R $RAILS_STACK_PATH/faye/config.ru start
4) RAILS_ROOT/faye/config.ru
require 'faye'
faye_server = Faye::RackAdapter.new(:mount => '/your_faye_mount', :timeout => 45)
Faye::WebSocket.load_adapter('thin')
faye_server.listen(<<PUT-YOUR-PORT-HERE>>)
Note that for part 4) the settings will be different based on your requirements of course.
If you follow the setup above, you'll have faye running alongside your stack, and it will be available as a process on your stack.

Ruby ON rails- Webrick

I am getting the following error while giving the "rails s" command in my cmd. the error is given in the link.
i am using mongodb as my database and not mysql.'pls suggest what to do
http://paste.kde.org/742976
-- Relevant Clip ---
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require': Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (cannot load such file --sqlite3/sqlite3_native) (LoadError)
Assuming you are using a ODM like Mongoid you will need to get rid of ActiveRecord in order to use MongoDB properly.
Instructions here should be helpful: http://mongoid.org/en/mongoid/docs/installation.html
Open myapp/config/application.rb and near the top, remove the line require "rails/all"

database configuration does not specify adapter

I'm getting this error when I'm trying to connect to a mysql database. The problem is that the application works for weeks, and then randomly I get this message. When I get this error message the application is not able to reconnect to the database until I restart it.
I'm using a configuration file to connect to the database, and the adapter is specified...the database configuration is not generated at runtime.
Do you have any idea on what is going on?
when I tried to run a command line script (let's say 'my_script' here), the same error happened. The reasons were:
There is only production environment there.
I missed to set RAILS_ENV for the command line.
So, the following is the solution in my case:
$ RAILS_ENV=production my_script
I just had this problem, and it was caused by a typo in my configration.yml.
I originally had this:
production:
adapter:mysql
When I meant to have this:
production:
adapter: mysql
That one little space between adapter: and mysql makes the difference.
Another possible cause:
In Rails 3.2.x, establish_connection has a default argument set from the environment:
From connection_specification.rb:
def self.establish_connection(spec = ENV["DATABASE_URL"])
resolver = ConnectionSpecification::Resolver.new spec, configurations
spec = resolver.spec
The way ConnectionSpecification::Resolver works depends on ENV['DATABASE_URL'] giving a nil if not set. (Normally, it would be something like 'postgres://...').
So, if you happen to have misconfigured DATABASE_URL such that ENV['DATABASE_URL'] == '', that will give you database configuration does not specify adapter.
I had this error when I mistakenly started rails server with
sudo rails s -e "Production" -p 80
and I should have started rails with
sudo rails s -e "production" -p 80
I found another thing that can cause this problem: "mixing in" another YAML node using & and *.
I was originally doing something like the following to facilitate local, per-develop, Git-ignored config files:
http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams
But, after some debugging, I came to find out that establish_connection was for some reason being called with only the mixed-in key-value pairs and not the main ones. I.e. adapter, host, and database were not being passed in. I have no idea why, and this used to work for me.
Anyhow, instead of mixing in another YAML node, I now put the entire development and test hashes in the local config file, and establish_connection is once again being called correctly.
For me, this command resolved the issue.
rake db:migrate RAILS_ENV=production
I've found a couple of clues that this might be related to older library (ActiveRecord) or gem versions. For example, problems with fixtures even though rest of app seems okay (after an upgrade) or this trac ticket, which "stops gems from requiring an adapter from an old Active Record gem". Both of these are old, though, but it might be worth making sure your gems are up to date (if possible).
Are you using the native rails MySQL adapter by any chance? This is now deprecated under rails, but it's conceivable it's still limping along.
I've taken a very quick look at connection_specification.rb, too, which is where this error is coming from, and my best guess is that a reconnect is failing... but why (since it was obviously okay when you first started the app)? Are you doing something wild like calling ActiveRecord::Base.establish_connection in your application controller (or elsewhere)?
Or perhaps something like: script runner is called from cron in the dead of night when the connection has dropped. Unfortunately, the runner is invoked with an incorrect RAILS_ENV. Thus the wrong stanza is read from database.yml, and that stanza contains an invalid adapter:?
I got the same error, by typing in the following command:
db:migrate RAILS_ENV=product
Should've been:
db:migrate RAILS_ENV=production
If you get this error while deploying with Capistrano. Make sure you are setting the correct RAILS_ENV via
set :rails_env, 'production'
For example I was not explicitly setting the Rails environment in for the Capistrano staging deployment configuration. And thus Capistrano used 'staging' as the RAILS_ENV, resulting in the above error. Setting it to production like above in the staging.rb file solved the issue.
Do remember that RAILS_ENV=staging will look for a staging specification in your database.yml just as setting RAILS_ENV=production will look for a production specification in database.yml file.
Provide database configs, as shown below, for every rails environment you target using, for example
bundle exec cap staging deploy
production:
adapter: mysql2
encoding: utf8
database: rails
username: rails
password: pass
host: 127.0.0.1
port: 3306
pool: 5
timeout: 5000
staging:
adapter: mysql2
encoding: utf8
database: rails
username: rails
password: pass
host: 127.0.0.1
port: 3306
pool: 5
timeout: 5000
Remember to use the C-Based ruby gem for mysql. The ruby-based is unstable for production.
Try installing the gem
gem install mysql
Remember to copy libmySQL.dll into the ruby bin directory.
I had this error with another problem; I had specified 'development' twice, and 'test' not at all.
There are alot of bad tutorials out there on the internet that show yaml files like so:
development:
encoding: utf
database: dbname
...etc
YAML files are case sensitive and require TWO SPACES for the inner contents of each given db-type attribute. Like so:
development:
encoding: utf
database: dbname
...etc
UPDATE: I got this error again today. My VPS server had installed Rails 3.2.8 when my app was running Rails 3.2.6.
Definitely check your Gemfile and your database.yml file (of course). The problem here is clearly stated---Rails is not communicating with your database specifically due to an adapter (aka gem)
We had this issue with one of our older apps. Someone had created a boutique named environment, that even if RAIL_ENV was set to production, it was looking for a database configuration called legacy_<RAIL_ENV>, so I had to make a database environment called legacy_production for this app to work.
If you are maintain someone else's app, I would look for a copy of this app's database.yml that is working, perhaps it has some oddly named configuration. You can search your codebase for establish_connection to see if it is defining some strange variant.
I met this problem due to the 'multiple database support issue'. In my app/model folder, there is a file defined a redundant database connection:
class CacheCleanerActiveRecord < ActiveRecord::Base
establish_connection "cache_cleaner_#{Rails.env}"
self.abstract_class = true
end
but this database is not found in my database.yml ( because it's not used at all ).
so the solution is quit simple: remove this file and everything is fine !
You may have an error like:
RAILS_ENV= test
A space after the equals sign is not allowed, change it to:
RAILS_ENV=test
This happens to me, finally I found that RAILS_ENV is case sensitive, in my enviroment I set
RAILS_ENV=DEVELOPMENT , which is wrong, the value of RAILS_ENV must be lowercase.
$ RAILS_ENV=DEVELOPMENT rails server webrick
=> Booting WEBrick
=> Rails 4.2.5 application starting in DEVELOPMENT on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
Exiting
/home/fangxing/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/connection_specification.rb:248:in `resolve_symbol_c
onnection': 'DEVELOPMENT' database is not configured. Available: ["default", "development", "test", "production"] (ActiveRecord::AdapterNotSpecified)
from /home/fangxing/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/connection_specification.rb:211:in `res
olve_connection'
$ RAILS_ENV=development rails server webrick
RubyDep: WARNING: Your Ruby is outdated/buggy. (To disable warnings, set RUBY_DEP_GEM_SILENCE_WARNINGS=1)
RubyDep: WARNING: Your Ruby is: 2.3.0 (buggy). Recommendation: install 2.3.1.
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-07-20 16:41:09] INFO WEBrick 1.3.1
[2016-07-20 16:41:09] INFO ruby 2.3.0 (2015-12-25) [x86_64-linux]
[2016-07-20 16:41:09] INFO WEBrick::HTTPServer#start: pid=19881 port=3000
rails -e "production" is okay
only rails -e production returns error
database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
call rake assets:precompile:all
This is probably not the most likely issue to cause this error, but here it is just in case.
My problem was that I was building the database settings in a Hash using symbols as keys and then serializing it with #to_yaml to database.yaml. ActiveRecord expects the environment names to be Strings, not Symbols, so it wasn't picking up the database settings when reading the generated file. I fixed it by using string keys in the hash.
For Rails4, commenting the line fetch(:default_env).merge!(rails_env: 'production') in production.rb and adding set :rails_env, :production fixed it.
You need to specify the environment when running the server or command as your database.yml file may have only production adapter while simply runnig rake db:migrate for example will take environment variable as development.
Just for the sake of completeness, I just got this error because I natively created a parametrised Rails runner script that takes an email address, and named the command line option -e -- which of course is the one the Rails runner uses for the environment. So it was trying to find an environment configuration that matched the email address!
Luckily, just before the ActiveRecord error mentioned in the title, it gave me an error message that helped me twig what the problem actually was:
You did not specify how you would like Rails to report deprecation notices for your test#example.com environment, please set config.active_support.deprecation to :log, :notify or :stderr at config/environments/test#example.com.rb
Check the spelling of adapter I had adaptor and got this error.
I had this error message when upgrading from Rails 4 to 5. I was calling
establish_connection "myconnection"
where "myconnection" is a valid key in my database.yml. However, passing this parameter as a string is apparently no longer supported. Using a symbol instead got rid of the problem.
I got this from copying and pasting sudo rails server webrick –e production -d from documentation into the CLI.
I'll shut the door on my way out 😔

Resources