When running Rails 3 RC with Ruby 1.9.2.rc2 under RVM I keep getting a very large number of errors from the MySQL driver bundle that look like this:
/opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant MysqlRes
/opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant MysqlField
/opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant MysqlError
/opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant VERSION
/opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant OPT_CONNECT_TIMEOUT
/opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant OPT_COMPRESS
/opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant OPT_NAMED_PIPE
/opt/local/rvm/gems/ruby-1.9.2-rc2/gems/mysql-2.8.1/lib/mysql_api.bundle: warning: already initialized constant INIT_COMMAND
This shows up in rails console and unit tests, anything that requires the full Rails stack, but not a script that uses Sequel directly in the same environment.
Although the bundle itself does load and the MySQL driver does work, this enormous pile of warnings prefaces anything run through Rails. Usually this results from a redundant load of the mysql gem somewhere within the Rails environment. The gem is declared in the Gemfile:
gem 'rails', '3.0.0.rc'
gem 'haml'
gem 'sequel'
gem 'mysqlplus'
gem 'mysql'
I'd suppose this is the Rails autoloader failing to understand the Mysql library has already been loaded, and loading it again. Is there an easy way to fix this?
Update:
Load mysql or mysqlplus but not both at the same time or you will get warnings like this. mysqlplus includes all of the functionality of mysql and is a dependency of Sequel.
Do you need the mysqlplus gem? I am using Rails 3 with only mysql 2.8.1:
gem 'mysql', '2.8.1'
Although I have not used mysqlplus, I am guessing that it sets the constants you are seeing in the warnings, and then the mysql gem sets these constants again when it is loaded.
UPDATE: Use mysql2 instead
#gem 'mysql', '2.8.1'
gem 'mysql2'
You also need to update your database adapters in database.yml:
development:
#adapter: mysql
adapter: mysql2
database: somedatabase_development
Related
I am getting a ton of warnings from ruby vips when running my test suit. Not causing any issues... just really annoying. Does anyone know the root issue here or know how to suppress the ruby vips warnings?
ruby '3.1.2'
gem 'rails', '~> 7.0.4'
gem 'image_processing', '~> 1.2' # ruby vips is a depency here. Gemfile.lock has ruby-vips 2.1.4 installed
When running tests (mini tests) I get this. Has anyone else seen this?
/Users/clarktaylor/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:51: warning: already initialized constant GLib::G_FREE
/Users/clarktaylor/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:51: warning: previous definition of G_FREE was here
/Users/clarktaylor/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/ruby-vips-2.1.4/lib/vips.rb:59: warning: already initialized constant GLib::LOG_FLAG_RECURSION
...
The warning go on for about 80 lines. Any help would be greatly appreciated!
Looks like it was an issue when setting the defaults for the image_processing gem. The default used supposed to be image_magick... however with rails 7, the default for active storage is ruby-vips. I tried adding config.active_storage.variant_processor = :mini_magick to config/application.rb but it made no difference.
HOWEVER, when I added config.active_storage.variant_processor = :mini_magick to config/environments/test.rb, it fixed the issue.
I went ahead and added that line to ALL my environment files just to be safe.
NOTE: ruby-vips is much faster than image_magick so it's probably best to keep ruby-vips. If you keep ruby-vips however, it does have a different syntax for creating variants
I have just scaffolded a Rails 5 app but the gemfile does not have any Mongodb gem or even the database.yml file does not even have any mongoDB. But when i run 'rails s' command it always outputs an error
Could not load 'active_record/connection_adapters/mongodb_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
Not able to understand how to even debug this as even google search does not point towards any meaningful solution
Any pointers would be greatly appreciated. Thank you in advance
While trying to run a rails app, I am getting the following error
rails s -p 5000
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: already initialized constant Net::SMTPSession
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: previous definition of SMTPSession was here
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/pop.rb:687: warning: already initialized constant Net::POP
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/pop.rb:687: warning: previous definition of POP was here
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/pop.rb:688: warning: already initialized constant Net::POPSession
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/pop.rb:688: warning: previous definition of POPSession was here
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/pop.rb:689: warning: already initialized constant Net::POP3Session
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/pop.rb:689: warning: previous definition of POP3Session was here
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/pop.rb:702: warning: already initialized constant Net::APOPSession
/home/user/.rvm/gems/ruby-2.1.6/gems/tlsmail-0.0.1/lib/net/pop.rb:702: warning: previous definition of APOPSession was here
/home/user/.rvm/gems/ruby-2.1.6/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'activeadmin'. (Bundler::GemRequireError)
What causes a Gem Require error in bundler?
I hope its trying to load activeadmin
May be the problem in activeadmin
check the gemfile and installation
gem 'activeadmin'
Use this to install activeadmin : Active admin install with Rails 4
It seems like you have multiple versions of the gem tlsmail being installed/loaded. That is the reason, you get the warning of it being already initialized. What you can do is run:
gem list --local | grep 'tlsmail'
which will return a list of versions of the gem installed. Then you can remove one of the versions (as per the dependency of your project) and see if that works.
gem uninstall tlsmail -v <version>
You might also want to check, whether you have same gem with different versions in the Gemfile.
Hope that helps!
Did you initialize your gemset? (Because you're using RVM)
Initialize your gemset as follows before running server,
rvm use ruby-2.3.0#rails425
replace the version of ruby and the name of gemset with your version of ruby and name of gemset.
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.
After I installed the tlsmail gem for email delivery to my gmail account, these erros keep coming up every time I run a rake command:
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: already initialized constant SMTPSession
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:687: warning: already initialized constant POP
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:688: warning: already initialized constant POPSession
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:689: warning: already initialized constant POP3Session
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:702: warning: already initialized constant APOPSession
How can I get rid of these warnings?
gem 'rails', '3.0.10'
gem "rake", "0.8.7"
gem "pg", "0.12.0"
gem "cancan", "1.6.7"
gem "geocoder", "1.0.5"
gem "will_paginate", "3.0.2"
gem "rails3-jquery-autocomplete"
gem "jquery-rails", "1.0.19"
gem "dynamic_form", "1.1.4"
gem "devise", "1.5.3"
gem "thin", "1.3.1"
gem 'sunspot_rails', '1.2.1'
gem "tlsmail"
If you don't want to modify the gem, try this:
require 'net/smtp'
Net.instance_eval {remove_const :SMTPSession} if defined?(Net::SMTPSession)
require 'net/pop'
Net::POP.instance_eval {remove_const :Revision} if defined?(Net::POP::Revision)
Net.instance_eval {remove_const :POP} if defined?(Net::POP)
Net.instance_eval {remove_const :POPSession} if defined?(Net::POPSession)
Net.instance_eval {remove_const :POP3Session} if defined?(Net::POP3Session)
Net.instance_eval {remove_const :APOPSession} if defined?(Net::APOPSession)
require 'tlsmail'
Preloading the net/smtp and net/pop gems and killing the constants prevents tlsmail from trying to load and write over the constants. It's a filthy, filthy hack ... but it works!
(Ruby 1.9.2, tlsmail 0.0.1)
At least, it seems, that you're not alone. I'm not terribly familiar with that gem, but it looks like this might be a fix for you: http://blog.snootymonkey.com/post/892799550/already-initialized-constant-warnings
It's possible that ActionMailer (or some other mailer code/plugin) is included by default as part of Rails 3. Don't quote me on that, but that's my unsubstantiated hunch as far as where the conflicting names might be coming from.
tlsmail was a backport of ruby 1.9 mail to 1.8. So you don't need tlsmail in ruby 1.9 or later.
This library dynamically replace net/smtp and net/pop with these in ruby 1.9 and
enables pop or smtp via SSL/TLS.
http://rubydoc.info/gems/tlsmail/0.0.1/frames