uninitialized constant MysqlCompat::MysqlRes (NameError)
If you get a stacktrace complaining about uninitialized constant MysqlCompat::MysqlRes
a system library update might broke your gem.
You might have switched from MySQL to MariaDB, but forgot to rebuild your MySQL gems.
Try fully removing and re-installing the gem:
gem uninstall mysql mysql2
bundle install
Related cards:
Fixing "uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)"
RubyGems 1.6.0 has undergone some changes which may cause Rails 2.x applications to break with an error like this one (e.g. when running script/server):
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:55: uni...
Fix capistrano errors: "no such file to load -- net/ssh/authentication/agent/socket" or "uninitialized constant Net::SSH::KnownHosts::SUPPORTED_TYPE"
There is a conflict between current capistrano versions and the 2.5.1 net-ssh gem. Make sure you upgrade to 2.5.2, then it should work again.
Namespacing: why `uninitialized constant` error may occour in `development` but not in `test` environment
Example:
class Book::Page
end
class MyBook < Book
def new_page
Page.new # has to be `Book::Page` in development to make it work
end
end
Method new_page
may throw an error when it was called during browser inte...
Top-level constants in BasicObject
If you want to access top-level constants inside a BasicObject class, you need to prefix them with ::
.
This will not work
class Foo < BasicObject
def bar
Hash.new
end
end
Foo.new.bar # => NameError: uninitialized constant Foo::Has...
How to stub class constants in RSpec
Hint: There's another card with this helper for Cucumber features.
Sometimes you feel like you need to stub some CONSTANT you have d...
Ruby constant lookup: The good, the bad and the ugly
In Ruby, classes and modules are called constants. This card explains how Ruby resolves the meaning of a constant.
The good
E. g. in the following example, Array
could mean either Foo::Array
or simply Array
:
class Fo...
How to define constants with traits
When defining a trait using the Modularity gem, you must take extra steps to define constants to avoid caveats (like when defining subclasses through traits).
[...
How to overwrite and reset constants within Cucumber features
In order to save the original value of a constant, set the new value and restore the old value after a scenario was completed, you can use the following helper. It takes care of saving the old constant value, setting the new one without throwing w...
Everything you ever wanted to know about constant lookup in Ruby
If you ever wondered why a constant wasn't defined or wasn't available where you expected it to be, this article will help.
Also see Ruby constant lookup: The good, the bad and the ugly.
Fixing "undefined local variable or method `version_requirements' for #<Rails::GemDependency:0x...> (NameError)"
Phillip Koebbe from Ruby on Rails suggested inserting following code between the "bootstrap" and "initialize" sections of enviroment.rb
. This hack fixes the problem.
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
...