I have an application using Rails 2.3.4 which I'm trying to run. No matter how I start it, by using script/console or script/ferret_server, it always boils down to the same error:
uninitialized constant Gem
When I search online, I only find people who has a similar problem finding something inside of the Gem class. But in my case, Gem is just not there at all.
I am running Ruby on Ubuntu. I tried using the version of Ruby that came with APT and a more recent one with RVM. Nothing helped.
Any idea how what can be causing thing and how to fix it? Thanks in advance!
Some extra details, as requested by commenters:
Output of ruby -v:
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03
Output of gem -v:
1.8.6
Calling ruby script/console outputs a similar error (edited):
Loading development environment (Rails 2.3.4)
/var/www/sites/example.com/releases/20110726061310/config/environment.rb:12:NameError: uninitialized constant Gem
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:254:in `require': no such file to load -- console_app (LoadError)
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:254:in `load_modules'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:252:in `each'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:21:in `setup'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb.rb:54:in `start'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/irb:17
I'm trying to call Ferret Server to allow Passenger to connect to it, with the command:
ruby --debug script/ferret_server -e production start
Outputs the following error:
Exception `NameError' at ./script/../vendor/plugins/acts_as_ferret/lib/../../../../config/environment.rb:12 - uninitialized constant Gem
uninitialized constant Gem
Alternatively, calling bundle exec ruby --debug script/ferret_server -e production start outputs the following error:
superclass mismatch for class GemDependency
Please note that I added the following right above the Rails::Initializer.run do |config| line in config/environment.rb:
require 'thread'
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
def requirement
r = super
(r == Gem::Requirement.default) ? nil : r
end
end
end
end
require File.join(File.dirname(__FILE__), 'boot')
Remove the lines mentioned above gives uninitialized constant Rails errors instead.
Try putting:
require 'rubygems'
Just after require 'thread'
Related
Ok I'm not a pro at creating gems, but I tried my best and created this gem https://rubygems.org/gems/webpack_native/versions/0.2.0
This gem has generators and if I use it from the local folder (meaning the gem folder is in my computer) it works fine, if I type rails g in terminal it shows me the generators including my gem's generators
But using it from rubygems always give me an error uninitialized constant WebpackNative:
/home/mody/.rvm/gems/ruby-2.7.0#myapp/gems/bootsnap-1.4.8/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `block in load_missing_constant': uninitialized constant WebpackNative (NameError)
any thoughts on this?
I'm not sure how this happen but I get it to work after I installed devise gem and run
rails g
the output of the available generators shows up including my gem, and the generator itself is working.
When I try any of the rails, rake command in staging server I got no such file to load -- ap (LoadError),
for rails s:
/usr/local/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in`require': no such file to load -- ap (LoadError)
xxxx
/config/application.rb:7
for rake -T:
rake aborted!
no such file to load -- ap
my application.rb file:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
my rails and ruby version:
rails version in local and staging: 3.0.11
ruby version in staging: ruby 1.8.7 (2012-02-08 patchlevel 358)
ruby version in local:ruby 1.8.7 (2011-06-30 patchlevel 352)
But I can run rails s, rails c, rake log:clear everything in my local machine. Gemfile file in staging is same as Gemfile in local.
what am I missing here? how can I resolve this?
In your Gemfile, change this line:
gem "awesome_print", :require => "ap"
...to this:
gem "awesome_print"
I just had the same thing happen to me. ap is a custom defined alias for awesome_print. This allows you to do things like ap Product.first and it will pretty print it for you. Much easier than typing out awesome_print Product.first
I'm not sure why, but when this happened to me, I dropped the alias, and it loaded without an issue. There is probably something else in play here that someone smarter than myself can explain, but I know that this worked for me.
I am getting this error uninitialized constant YAML::ENGINE error when i run rake db:migrate . I have the ruby version ruby 1.9.3p327 and rails version Rails 3.0.20, my gems version is 1.8.25. can anyone please help that whats wrong.
this is how my config/boot.rb file looks like
require 'yaml'
YAML::ENGINE.yamler= 'syck'
on this second line I am getting this error.
I am trying to use the twitter-text-rb (https://github.com/twitter/twitter-text-rb) in my Rails 3 app.
I installed it using bundler and my gemfile - seemingly successfully - but when I try and include its autolink function in my Application Helper, like this:
require 'twitter-text'
module ApplicationHelper
include Twitter::Autolink
end
I get this error in the browser when I try to load the root of the app:
Routing Error
uninitialized constant Twitter::Autolink Try running rake routes for
more information on available routes.
I've followed these Troubleshooting Questions within the Ruby Gems manual but it doesn't seem to be either of the two likely issues that they suggest under "Why does require 'some_gem' fail?".
Here's the extract from when I followed their instructions from the root of my app using terminal:
manager$ gem list twitter-text
*** LOCAL GEMS ***
twitter-text (1.5.0)
manager$ ruby -rubygems -e 'require "twitter-text"'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `gem_original_require': no such file to load -- twitter-text (LoadError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `require'
from -e:1
manager$ gem contents --no-prefix twitter-text | grep lib
lib/twitter-text.rb
lib/twitter-text/autolink.rb
lib/twitter-text/deprecation.rb
lib/twitter-text/extractor.rb
lib/twitter-text/hit_highlighter.rb
lib/twitter-text/regex.rb
lib/twitter-text/rewriter.rb
lib/twitter-text/unicode.rb
lib/twitter-text/validation.rb
manager$ ruby -rubygems -e 'require "twitter-text"'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `gem_original_require': no such file to load -- twitter-text (LoadError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `require'
from -e:1
manager$ which ruby
/usr/bin/ruby
manager$ gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
I'm using and handful of other gems in the app and haven't run into similar problems before.
I'm at a loss as what to try next. I'm pretty new to Ruby/Rails (and programming in general for that matter!) so any help would be much appreciated.
thanks,
Matt
I've now got this gem working and removed the Load Error (although I can't say for sure what went right).
I installed RVM and tried my app and the twitter_gem using Ruby 1.9.2 and Rails 3.2.3. I was previously using the system default Ruby - 1.8.7 - and Rails 3.2.3. The gem was loaded correctly and worked perfectly.
So it seems like the problem was with the gem working on the earlier version of Ruby or RVM's gemsets helped the app to load the gem correctly.
i have the code belowin the environment.rb and i keep getting the error uninitialized constant YAML::ENGINE (NameError) when i try to run it.
environment.rb
require 'yaml'
YAML::ENGINE.yamler= 'syck'
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Quora::Application.initialize!
anybody have an idea?
YAML::ENGINE doesn't exist in Ruby 1.8.7. This is defined in Ruby 1.9. I tried running irb on 1.8.7 and 1.9.2. Strange though, both of their YAML version number is the same (0.6.0).
Also, I think Ruby 1.8.7's YAML already uses SYCK for yaml parsing. :)