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
Related
I get the following error when I try to start up rails or if I run rails console.
.rvm/gems/ruby-2.3.3#adventure_map/gems/godmin-tags-1.0.1/lib/godmin/tags/helper.rb:11:in '<module:Godmin>': uninitialized constant Godmin::FormBuilders (NameError)
I have included the gem godmin-tags , using haml for templating and running rails-5.0.1
No issue has been raised on its github page and I can seem to find a solution to this
Part of my Gemfile is:
gem 'godmin-tags'
gem 'godmin' # administrative interface https://github.com/varvet/godmin
gem 'devise_token_auth'
gem 'omniauth'
Make sure you include godmin-tags after godmin ;-)
I'm using a gem for gmail in my Rails app. My Gemfile contains:
gem 'gmail-api-ruby', :require => 'Gmail'
And in my controller, I initialize the gem with (using devise/omniauth to get the refresh_token from Google):
Gmail.client_id = ENV['CLIENT_ID']
Gmail.client_secret = ENV['CLIENT_SECRET']
Gmail.refresh_token = current_user.refresh_token
This works fine in development, but when I deploy to Heroku, I get the following error:
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in `require': cannot load such file -- Gmail (LoadError)
I cannot figure out why. Should I be requiring the gem somewhere else in my app?
Ruby 2.2.0
Bundler: 1.8.5
Rails: 4.2.0
require is case sensitive if the underlying filesystem is case sensitive (which it is on linux, which is what underpins heroku)
Change to :require => 'gmail' instead of Gmail and you should be ok.
Just remove useless require option from your Gemfile because bundler can load classes inside of this gem without specify require option in your case.
gem 'gmail-api-ruby', '~> 0.0.10'
and run bundle install.
FYI: read section about require option here.
In my Gemfile I have:
gem 'addressable'
In search_controller.rb:
uri = Addressable::URI.new
uri.query_values = {:q => query}
I get this error:
NameError (uninitialized constant SearchController::Addressable):
If I put
require 'addressable/uri'
on top of my controller, it works!!. I have already done "sudo bundle install" and it shows addressable is installed. What am I doing wrong?
Looking at addressable gem source I see it has no lib/addressable.rb which is default file which rubygems or bundler require when loading required gem. So it looks like it is designed this way on purpose - to make you explicitly require only the libraries you need.
I just created a new gem (using bundler) and want to add Active Record support. So I added s.add_dependency "activerecord", "~> 3.0" to my gemspec. Then I use Bundler.setup and Bundler.require and thought that I have access to Active Record now, but I haven't. I have to explicitly use require "active_record". Any idea why Bundler.require does not work for me in that case?
Firstly, if you're packaging a gem, do not use Bundler.require. Bundler.require is for apps not gems.
In .gemspec, specify the dependencies of your deployed gem.
In your Gemfile, include the line gemspec to automatically include the dependencies listed in your .gemspec in your Gemfile.
You may also optionally create gem groups for dev and test.
In your code, explicitly require any libraries you need.
I lost a couple of hours on this today so I hope this helps.
(Sources 1, 2)
Secondly, though the ActiveRecord gem is called "activerecord", the lib is called "active_record". This is what you would need in Gemfile.
gem 'activerecord', :require => "active_record"
Unless you include the :require option, ActiveRecord won't be loaded correctly and you won't know about it until you try to use it.
If you want use Bundler you need define your Gemfile with Activerecord
gem 'activerecord', "~> 3.0.0"
Or you need define bundler to use your gemspec with adding gemspec in your Gemfile
gemspec
See http://gembundler.com/rubygems.html
I had this problem, and the issue in my case was that I was naming a directory in my gem active record, as in:
lib ->
active_record ->
base.rb <- containing some monkey patches to base
This was causing mass confusion including sweet error messages like:
Gem Load Error is: uninitialized constant ActiveRecord::Base
Did you mean? ActiveRecord::Base
Simply moving changing the file from lib/active_record/base.rb to lib/active_record_base.rb fixed it for me.
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