dm-mysql2-adapter (LoadError) but why? - ruby-on-rails

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

Related

Can add Gemfile and Gemfile.lock to git

I am trying to deploy my app to Heroku.
I removed the 'sqlite3' gem and added the following part to my Gemfile:
gem 'sqlite3', group: :development
group :production do
gem 'pg'
gem 'rails_12factor'
end
After that, I ran bundle install to update it. However, when I try to do git add, it said:
error: insufficient permission for adding an object to repository database.git/objects
error: Gemfile.lock: failed to insert into database
error: unable to index file Gemfile.lock
fatal: updating files failed
If I delete the code I added in the Gemfile, everything works just fine!
I'm running on OSX 10.11.1, Rails 4.2.4, ruby 2.2.1p85 and git 2.4.9 (Apple Git-60).
The issue is probably because your config/database.yml needs to be configured to use postgresql instead of sqlite.
I highly suggest using postgres for both production AND development by removing the gem 'sqlite3', group: :development from your gemfile and just add gem 'pg' outside of the production group (so it applies to all environments: dev, prod, and test).
Then in your database.yml, in the default: &default section, change adapter to:
adapter: postgresql
Or if you want to continue using sqlite in dev, just change the production: section in your database.yml to the following:
production:
adapter: postgresql
encoding: unicode
pool: 5
You might need to change the database: value to something like:
database: your_app_name_production
where "your_app_name" is the name of your app.
NOTE: Be sure to keep the spacing exact as YAML files are whitespace sensitive.
Hope that helps.
Or it could be something wrong with your Gemfile.lock.
You should be able to safely delete that file (make a backup copy first, just in case). Use git rm Gemfile.lock. Gemfile.lock just tracks all the versions of all the gems installed in your project based on the latest version at the point in time you first bundle installed them.
Then when you run bundle install it will automatically generate a new one.
Then do a git add -A again (better to use that than git add *).

Why is my rails server issuing deprecation warning and not connection to sqlite3?

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.

Rails database configuration does not specify adapter. What do I do?

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

Rails Oracle enhanced adapter

I am having issue connecting from ROR 3.2 to Oracle database.
irb(main):001:0> gem 'ruby-oci8', "~>2.1.0"
=> true
irb(main):002:0> gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.1'
=> true
irb(main):003:0> exit
rails console
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require':
Please install the oracle_enhanced adapter: `gem install activerecord-o
racle_enhanced-adapter` (cannot load such file -- active_record/connection_adapters/oracle_enhanced_adapter) (LoadError)
I searched the web and it says i should create a gems file located at
https://github.com/rsim/oracle-enhanced/blob/master/Gemfile and then do a bundle install .
But i am new to rails and not sure how to do this any ideas please.
C:\kerbapp>bundle show activerecord-oracle_enhanced-adapter
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.4.1
A rails application since 3.0 comes integrated with package management for gems called bundler (I recommend reading up more here). Any application will see only the gems included in its package list.
Your project should have a Gemfile file - add the gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.1' line there, run bundle command from project root directory, and it should be good to go.
Keep in mind that when working with rails (and any sizable ruby project really) you should be adding all gems this way.

Deploying Rails to Heroku on Windows, postrgres error

Rails 3.2.1, Ruby 1.9.3
I can push my app to Heroku, but when I navigate to the page it fails. This is from the logs:
"Unexpected error while processing request: Please install the postgresql adapter: 'gem install activerecord-postgresql-adapter'"
I have already run that command locally and it worked.
I am using sqlite3 for dev, my gemfile looks like this:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'thin'
gem 'pg'
end
Any idea what I am doing wrong/how to fix this? thank you!
I'm getting the same sort of error with the same sort of config.
2013-04-05T08:06:12+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2013-04-05T08:06:12+00:00 app[web.1]: !! Unexpected error while processing request: Please install the postgresql adapte
r: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
Have found that doing an update to the Gemfile (just adding whitespace) gets around the problem. It's a hassle though since it needs to be done every time any change is done.

Resources