The following is the error message:
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection'
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
...
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `eval'
/Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `<main>'
My database.yml file:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
My Gemfile:
source 'https://rubygems.org'
gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
gem "twitter-bootstrap-rails"
gem 'jquery-rails'
gem 'devise'
gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
gem 'mini_magick'
gem "rmagick"
gem "carrierwave"
# 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'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
I solved a similar problem in a somewhat intricate project. Not sure it's directly related, but I'm posting this as the way of debugging the problem may be helpful.
In my case, I had the following scenario:
The situation only occurred when RAILS_ENV=production. When I did RAILS_ENV=development it worked. Weirdly enough, when I changed the production entry in database.yml to production2 and ran the command with RAILS_ENV=production2, it worked.
In the project I was connecting to multiple database connections through various models and libraries.
Here is what I did to detect the issue:
vim /Users/davidzabner/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb
(or wherever the backtrace is telling you the issue is).
Then, I found the place in the code that has these lines:
def resolve_hash_connection(spec) # :nodoc:
spec = spec.symbolize_keys
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
And changed it to the following:
def resolve_hash_connection(spec) # :nodoc:
spec = spec.symbolize_keys
# Debug printing
puts "*" * 80, spec.inspect, "*" * 80
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
Then I reran the command, in my case bundle exec rails c production.
By doing this I realized that Rails wasn't looking for the production entry as I was thinking it was. It was looking for a different entry called abc_production, which was required in my project due to the multiple database connections I was referring to earlier. On that particular server someone forgot to add that abc_production entry to database.yml. Adding the entry solved the issue.
I believe it happened only when RAILS_ENV=production because in environments/production.rb I have config.eager_load = true, which means Rails will eager-load the application and classes to memory, and probably attempt to establish all database connections defined in those classes (one of them being abc_production).
Hope this helps someone in a similar situation... If you're not using multiple connections, try and debug the problem by changing connection_specification.rb and see if it gives you any lead..
i don't now exactly what you tried to do but.
currently i got the same error as i tried to run < rails c -e production > with ruby-2.10.
`resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
as i run < rails c production > everything works.
maybe this helps someone
I had a similar issue with staging environment and I did:
added devise secret to devise.rb initializer file
configured staging 'secret_key_base' in secrets.yml
It worked fine me there after.
I've crated an gist with a sample database configuration, please make sure you use it.
The gist is located at: https://gist.github.com/fidalgo/5970617
Also make sure you run rake db:setup to setup your database.
Also since in your environment you are using Sqlite for production and test too, in your Gemfile change this lines:
group :development, :test do
gem 'sqlite3'
end
to
#group :development, :test do
gem 'sqlite3'
#end
it shouldn't make any significant difference, except you are using other environment than development.
I met this problem too. I tried all similar questions I can find but none of them resolved my problem then I tried to print configurations system read from database.yml in activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb
def resolve_string_connection(spec) # :nodoc:
hash = configurations.fetch(spec) do |k|
connection_url_to_hash(k)
end
p configurations
p spec
raise(AdapterNotSpecified, "#{spec} database is not configured") unless hash
resolve_hash_connection hash
end
The output is
{"production"=>nil, " adapter"=>"mysql2", " encoding"=>"utf8mb4", " username"=>"myUsername", " password"=>"myPassword", " pool"=>5, " database"=>"mydb", " host"=>"myHost", " port"=>3306, "mydb_production"=>nil}
So my problem is there's something wrong in the database.yml causes YAML parse error. However I don't find anything wrong by my bare eyes so I copied a file from another server then problem resolved.
Hope this can help someone :p
Realise this is a little old, but have just come across whilst looking for an answer on a similar issue. Just wanted to point out that you still have sqlite3 as your adaptor in your .yml. As you have probably found out since, Heroku does not allow sqlite3 as a production db. SQLite on Heroku
Related
I have spend several hours looking for solutions to this on the web. Postgresql installation guides do not help since i am not familiar with interacting with databases only with ruby on rails and dealing with them this way.
I have made several simple rails application by following tutorials and am still learning rails. I am using Windows 10 and I have deployed some of these to Heroku for which i had to use the pg gem becasue Heroku doesnt use sqlite3. But I have read in several places that it is necessary to install postgresql locally. So i have installed it, i think, but now i am lost. I have a software called pgAdmin4 and now i have absolutely no idea what to do in order to use postgresql through rails. I started a new app just to test it by using the following command:
rails new postgresapp --database=postgresql
This has given me the basic starting point for a new app set up to use postgresql. the first error that I get when i try to connecct to the localhost3000 is:
PG::ConnectionBad
fe_sendauth: no password supplied
Extracted source (around line #56):
### Convenience alias for PG::Connection.new.
def self::connect( *args )
return PG::Connection.new( *args )
end
bearing in mind that i am not sure if the installation was a success. i went through the process of installation and entered a password and all the information so i assume that it did install somewhere.
also there are no servers showing on pgAdmin so i added one called localhost. i am not sure if this was the right thing to do or not.
gem file:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.6'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# 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.2'
# 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 navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# 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', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
database.yml
# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: postgresapp_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: postgresapp
# The password associated with the postgres role (username).
#password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: postgresapp_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass#localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: postgresapp_production
username: postgresapp
password: post#<%= ENV['POSTGRESAPP_DATABASE_PASSWORD'] %>
When you check what is in your database.yml file you need user and password configuration.
You have password as blank value.
I would suggest create a postgreSql user with password and use those credentials
You will need psql for accessing postgreSql from terminal, to create new user with permissions.
one of the links, you can find a lot more about this on the web.
But you problem is user and his password
After fixing you user and password problems, you will need to create the DB with the name from database.yml.
In you database.yml DB name is postgresapp_development. You will ne to create it. Find a client for windows to connect to you postgreSql with user and password you defined when installing and create the DB.
Check this for accessing you postgresSql server
I am starting rails by following this tutorial:
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-the_first_application
which seems very nice.
At the beginning, the author talks about the importance of the versions for the gems and softwares, so I did my best to keep using the exact same versions.
I followed the tutorial and it all ran nicely, the installation was ok (from his suggested source: http://railsinstaller.org/en )I downloaded ruby 1.9.
After installing, I used rails new first_app to create my app, changed the Gemfile to this one:
source 'https://rubygems.org'
ruby '1.9.3' #In the tutorial is 2.0.0, but changed to match my ruby version,
#as specified in the tutorial
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.1'
group :development do
gem 'sqlite3', '1.3.8'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
When I run rails server command, I get the following error:
DEPRECATION WARNING: config.whiny_nils option is deprecated and no longer works.
(called from block in <top (required)> at D:/rails/first_app/config/environment
s/development.rb:10)
config.eager_load is set to nil. Please update your config/environments/*.rb fil
es accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test enviro
nment)
* production - set it to true
But opening localhost:3000 works fine. Clicking on "About your application’s environment" link, generates an error
ActiveRecord::ConnectionNotEstablished
Rails.root: D:/rails/first_app
I checked and my database.yml is using sqlite3.
When I run rake db:create inside my app's folder, I get
rake aborted!
Specified 'postgresql' for database adapter, but the gem is not
loaded. Add gem 'pg' to your Gemfile.
I think that maybe these three issues are connected and the source of the problem is that error message when starting the rails server.
What can I do to fix it, could it be the ruby version 1.9.3 instead of 2.0.0?
thanks!
EDIT:
On this link, I found the solution for my issue on the whiny_nils deprecation
Rails 4 removed the whiny_nils feature. Read more about it in the ActiveRecord chapter.
To solve the deprecation warning, simply remove any lines that set config.whiny_nils. Rails 3 added the configuration by default in config/environments/development.rb and config/environments/test.rb by default.
No idea why creating an app and starting it with the same version would cause this problem, but ok. No.1 fixed :)
Edit2: In the same link, I fixed the config.eager_load issue by creating this config in my config files and setting a value.
The active record issue remains.
EDIT 3:
This is my database.yml file
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
Solved: I had a database_url pointing to a postgres DB in my system environment variables. I've done that when following an heroku tutorial long ago. I removed it and now it works fine.
I suggest a solution that I believe will work better for you:
Remove the version numbers from all of the gems other than rails
It will do rails 4 and ruby 2.0 and for you ruby 2.0 will probably work.
If necessary have the ruby version as 1.9.3
This would probably work better for you now and in the future.
It's better to avoid all those specific version numbers for other gems to avoid having.... the version problems you are experiencing. You want to spend less time on that and more time on the actual app, rails code, ruby code, etc. Most gems can figure out the right versions and dependencies themselves.
Try quickly doing another app this way (make sure you "cd .." out of this app first before issuing that rails new command again). You'll also see that doing a new app is a surprisingly frequent thing when compared to some other, older frameworks.
Hi I am about to deploy a rails app (onto heroku) I made and wanted to know what the procedure is. I know you have to change the database by changing gem 'sqlite3' to gem 'pg' but after I did that and went on my localhost:3000 it gives me the error:
ActiveRecord::ConnectionNotEstablished
What else am I missing?
You don't need to change gem. Database used in application on heroku default is postgres. Keep gem 'sqlite3' and add this in your Gemfile:
group :production do
gem "pg", "0.14.0"
end
the issue that I'm dealing with is the following. I've installed a brand new ruby environment. In my current project I'ld like to use the following gems:
RAILS_VERSION = '~> 3.0.4'
DM_VERSION = '~> 1.1.0'
gem 'rails', '3.0.9'
# Database & ORM
gem 'mysql2', '< 0.3'
gem 'data_mapper', DM_VERSION
gem 'dm-mysql-adapter', DM_VERSION
gem 'dm-rails', DM_VERSION
# Authentication
gem 'devise'
gem 'dm-devise'
I have the following database.yml:
defaults: &defaults
adapter: mysql2
encoding: utf8
reconnect: false
pool: 5
username: blabla
password: albalb
host: localhost
socket: /tmp/mysql.sock
Performing "bundle install" does not result into any kind of error. But as soon as I want to do some thing with the database (like "rails s", or "rake db:migrate") the folling error occurrs:
/Users/Gery/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require': no such file to load -- dm-mysql2-adapter (LoadError)
from /Users/Gery/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
from /Users/Gery/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/Gery/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/Gery/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'
from /Users/Gery/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require'
Do you have any idea how to solve this problem?
Best Regards,
Gerardo
I just went into #datamapper and solnic helped me understand this: there is no need to use the mysql2 gem with DataMapper, because do-mysql (the DataObject driver dm-mysql-adapter depends on to access MySQL repositories) doesn't have problems with character-encodings, which is the reason I (and most people, I would assume) use the mysql2 driver in ActiveRecord projects.
So the answer is, unless I'm mistaken about why you're using it, remove mysql2 from your Gemfile and your database.yml file (replace it with mysql) and do a new bundle install, you shouldn't need it.
This is a bug in dm-core as a result of sub-standard coding. I have committed a hack to fix this hack and submitted a pull request here: https://github.com/datamapper/dm-core/pull/154
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do you upgrade from Rails 3 to Rails 3.1 beta?
This is what worked for me when updating an existing rails 3.0.8 project. Your mileage may vary...
Update the rails version specified in my Gemfile to use the latest release candidate:
gem 'rails', '3.1.0.rc4’
Update the bundle:
bundle update
Then update the project with the rake command:
rake rails:update
After cherry picking though the change conflicts I ran all my tests and they passed (yay!). I restarted the server and everything seems good so far.
However, this is not using the new asset pipeline yet. By that I mean the javascript and css (or sass) files are still being handled in the pre-pipeline manner. As I understand it, this is a perfectly viable option. But of course, I want the new goodness, so I believe the next steps are to include and additional gems (e.g. coffeescript, sass, uglifier, etc) and then to migrate the old files to the app/assets directory.
I found some details about that are here:
http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/
Hope that was helpful.
I just upgraded from 3.0 to 3.1 by changing my Gemfile to:
gem 'rails', '3.1.0.rc1'
gem 'sqlite3'
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
I also commented out the following line below in config/environments/development.rb
# config.action_view.debug_rjs = true
Finally, make sure you enable the asset pipeline in config/application.rb
config.assets.enabled = true
I'm not sure if you've already read the release notes http://weblog.rubyonrails.org/2011/4/21/jquery-new-default
Upgrading Rails
Update: be cautious of using your system rake, as rake has been upgraded.
bundle exec rake
ensures you'll be using the correct rake for a given rails project (source)
I suggest beginning with a fresh app, then copying in your specific app information while shifting your resources into the new asset/sprockets format.
An example
While converting an older rails 2.3.4
app to 3.0 I crashed and burned while
changing one file at a time over
within the project. Needless to say
that was a flawed strategy, but I did
learn a little along the way. I ended
up skipping 3.0 and moving to 3.1beta1
with a fresh app, and copied my app
and public folders in after getting
the migrations right. That move had a
couple of outstanding issues, the most
important being that I didn’t use
rails edge for creating the new app
(thanks for the tip RubyInside).
First snag the latest rails into an
easy to reference location:
cd ~/goodtimes
git clone
https://github.com/rails/rails.git
My path includes a ~/Desktop/Dropbox/
so my code is available everywhere.
Then refer to that rails exec for
building a new app:
~/goodtimes/rails/bin/rails new bacon --edge
Depending on the complexity of your database, you'll either want to create new migrations using the change syntax or leave them be:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
end
end
I had an issue deploying to Heroku, but theRubyRacer gem helped square that away. Here's an example of a simple Gem file:
source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Asset template engines
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
gem 'pg'
gem 'therubyracer-heroku', '0.8.1.pre3', :platforms => :ruby
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
I suspect there will be community utilities to help you automate migration from older versions of Rails to the --edge.
References:
How to Play with Rails 3.1, CoffeeScript and All That Jazz Right Now
The Four Horsemen of Rails 3.1beta, Coffee-Script, jQuery, SCSS and Assets
Rails 3.1beta deployed to Heroku from your iPhone
Reversible Migrations
I recommend updating your Gemfile to use edge rails. For example:
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'sqlite3'
# Asset template engines
gem 'sass', '~> 3.1.0.alpha'
gem 'coffee-script'
gem 'uglifier'
You can read more here http://pogodan.com/blog/2011/04/24/easy-edge-rails.
If i understood your question correctly this is how:
gem install rails --pre