Rails 3 error: no such file to load -- initializer (LoadError) - ruby-on-rails

I'm on Ubuntu and my app is written for Rails 2.3.5 and I got it to run on 2.3.10 but when I upgraded to Rails 3.0.3 and tried to run it using "ruby script/server", it throws this error.
/usr/local/lib/site_ruby/1.8/rubygems.rb:230:in `activate': can't activate rails (= 2.3.10, runtime) for [], already activated rails-3.0.3 for [] (Gem::LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:35:in `require'
from /home/bob/savage/config/boot.rb:55:in `load_initializer'
from /home/bob/savage/config/boot.rb:38:in `run'
from /home/bob/savage/config/boot.rb:11:in `boot!'
from /home/bob/savage/config/boot.rb:110
from script/server:2:in `require'
from script/server:2
When I uninstalled Rails 2.3.10, it throws this error instead
bob#ubuntu:~/test.2.3.10$ ruby script/server
/usr/local/lib/site_ruby/1.8/rubygems.rb:777:in `report_activate_error': RubyGem version error: rails(3.0.3 not = 2.3.10) (Gem::LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems.rb:211:in `activate'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:1056:in `gem'
from /home/bob/test.2.3.10/config/boot.rb:60:in `load_rails_gem'
from /home/bob/test.2.3.10/config/boot.rb:54:in `load_initializer'
from /home/bob/test.2.3.10/config/boot.rb:38:in `run'
from /home/bob/test.2.3.10/config/boot.rb:11:in `boot!'
from /home/bob/test.2.3.10/config/boot.rb:114
from script/server:2:in `require'
from script/server:2
Ideas? Thanks in advance for your help.

I was getting the same error until I realized that I was still using the same old config/boot.rb from the 2.3.10 version of my app. I went into a clean directory and generated a new Rails 3.0.3 app and used the boot.rb it created. The file is totally different, and it got me past this error.

I have the same problem.
After reading the comments above, I tried creating a new, empty application in another directory:
rails new foo
cd foo
rails s
WEBrick starts up just fine. Perhaps Bob can duplicate this? This rules out problems with Rails and Ruby versions (3.0.3, 187p302 respectively for me). And it really points to problems with running Rails 3 utilities in directories with old versions of boot.rb or environment.rb, and running Rails 2 script files (plugin, server) once 3.0.3 is the active version of Rails.

This is the default Rails 3.0.0 config/boot.rb file. I would use all or parts of this instead of your config/boot.rb
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])

Noticed 1.8 in your path - I believe you'll need to be on 1.9.2 for Rails 3 to work. Use RVM to get this up and running right away.
Additionally - you typically start Rails 3 with 'rails server' or 'rails s' - you don't need to fire off script/server anymore. Give that a go and see how it works.

Related

Rails cannot load rubygems/defaults file on Windows

Versions, dependencies, and other information:
Ruby: 1.9.3p392 (2013-02-22) [i386-mingw32]
Rails: 3.2.13
Gemfile located at: http://pastebin.com/z9u40Jca
For some reason, whenever I run any gem based command, it gives me this error:
$ rails s
c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/rubygems.rb:30:in `require': cannot l
oad such file -- rubygems/defaults (LoadError)
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/rubygems.rb:30:in `<top
(required)>'
from <internal:gem_prelude>:1:in `require'
from <internal:gem_prelude>:1:in `<compiled>'
I have tried deleting ruby 2.0.0 from pik and the rails installer folder, because another SO thread said that would fix it. The commands were working as of 5 hours ago, and must have stopped right when I finished using the rails console (part of learning rails from this tutorial, it was just basic math and string manipulation, so I don't think I screwed something up). Any ideas on what I should do?
Try deleting 'ruby '1.9.3' ' from your gem file. It shouldn't be causing a problem, but I've seen situations where it has.
I don't know if I did something I don't know about, but to the best of my knowledge, adding the gem "bootstrap-sass" at version 2.3.2.0 got it working again. I doubt that it was adding that exact gem that was the solution, but you never know.

no such file to load -- initializer (LoadError)

I have following installed on ubuntu 12
ruby 1.9.2p320
Rails 3.2.6
Now I have old project which is developed into Rails 2 & Ruby 1.8.7
Problem:
When i run below command under old project root directory
ruby ./script/plugin install git://github.com/rails/rails_upgrade.git
Following error comes
Invalid gemspec in [/usr/local/rvm/gems/ruby-1.9.2-p320/specifications/ZenTest-4.9.1.gemspec]: Illformed requirement ["< 2.1, >= 1.8"]
/usr/local/rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require': no such file to load -- initializer (LoadError)
from /usr/local/rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /var/www/project/client/softwallet/config/boot.rb:54:in `load_initializer'
from /var/www/project/client/softwallet/config/boot.rb:38:in `run'
from /var/www/project/client/softwallet/config/boot.rb:11:in `boot!'
from /var/www/project/client/softwallet/config/boot.rb:109:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from ./script/plugin:2:in `<main>'
Upgrading the old rails project to new one and getting the invalid gemspec problem.
Then you have to do the following:
Run gem update --system followed by bundle install.
UPDATE:
You are using the same old config/boot.rb from your older version of rails application.
Do the following:
1) Create a new project directory.
2) Generate a new rails app (Of your new latest rails version)
3) Use boot.rb that is created by it.
This happens when you have incompatible version of the same gem already installed on your environment.
To rectify, either you can uninstall and reinstall the gem or install the gem of the specific version.
Make sure that you do a gem cleanup operation before doing so.
This is how my problem was solved . I was using RVM and if you have edited those .bashrc files then each time while you log in to the shell , do a /bin/bash --login . What this does is , it makes the command line take note of the rvm path you had set and installs them first .
I did this on Ubuntu 12 and it did solve my issue , i don't think doing gem update --system is a good idea as it really kind of messes up the environment forcing one to do an rvm implode and install it all over again .

Error with new Rails 3.2.8 project - `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)

I've just created a new amazon Linux instance and installed ruby 1.9.3 and rails 3.2.8.
Upon creating a new project I immediately receive failures due to sqlite3. The error is:
[root#xxxxx fun]# rails server
/usr/local/share/gems/gems/sqlite3-1.3.6/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)
from /usr/local/share/gems/gems/sqlite3-1.3.6/lib/sqlite3.rb:6:in `rescue in <top (required)>'
from /usr/local/share/gems/gems/sqlite3-1.3.6/lib/sqlite3.rb:2:in `<top (required)>'
I have confirmed that sqlite3 is working just fine outside of rails (i.e. I successfully created a database, did inserts/reads using ruby code). Here is a quick show of loading sqlite3 in irb:
irb(main):001:0> require 'sqlite3'
=> true
I'm all up to date with bundle install. sqlite3 is at version 1.3.6
I have the following packages installed:
ruby19-1.9.3.0-7.17.amzn1.i686
ruby19-devel-1.9.3.0-7.17.amzn1.i686
ruby19-irb-1.9.3.0-7.17.amzn1.noarch
ruby19-libs-1.9.3.0-7.17.amzn1.i686
rubygem19-io-console-0.3-7.17.amzn1.i686
rubygem19-rdoc-3.9.4-7.17.amzn1.i686
rubygems19-1.8.11-7.17.amzn1.noarch
sqlite-3.6.20-1.8.amzn1.i686
sqlite-devel-3.6.20-1.8.amzn1.i686
Any ideas on what I could try to get things working? Thanks!
Update
For "fun" I commented out the gem sqlite3 line from my Gemfile and tried "rails server" again. First it complained about not having a javascript runtime (which I could fix) but then it is getting the following. There seems to be something royally wrong with my install.
[root#xxxx fun]# rails server
/usr/local/share/gems/gems/railties-3.2.8/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `active_record' for #<Rails::Application::Configuration:0x9e68f58> (NoMethodError)
from /srv/rails/fun/config/application.rb:54:in `<class:Application>'
from /srv/rails/fun/config/application.rb:13:in `<module:Fun>'
from /srv/rails/fun/config/application.rb:12:in `<top (required)>'
You may have a path problem.
To see if you have more than one version of Ruby, Rails, or gem installed:
find / | grep bin/ruby
    find / | grep bin/rails
    find / | grep bin/gem
On Amazon servers, I typically keep the system Ruby as is, and install my own current Ruby by using the excellent ruby-build script (better than RVM, in my opinon).
https://github.com/sstephenson/ruby-build
If you do have more than one Ruby, I suggest that you set your environment to choose one, for example by using ruby-build or by setting your PATH in your .bashrc file or /etc/environment file something like this:
PATH=/opt/ruby/1.9.1-p134/bin;$PATH
If you're using RVM, I suggest you uninstall it and change to use ruby-build.
To uninstall RVM, I use this script:
https://github.com/SixArm/sixarm_unix_shell_scripts/blob/master/rvm-uninstall-danger

Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)

When I want to create a Ruby on Rails project, I get the message below.
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support.rb:57
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails_generator.rb:31
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.8/bin/rails:15
from /usr/bin/rails:19:in `load'
from /usr/bin/rails:19
What has gone wrong? How do I to fix it?
In case you can't upgrade to Ruby on Rails 2.3.11 (and to expand on douglasr's answer), thread must be required at the top of boot.rb. For example:
require 'thread'
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
...
I was able to fix this by downgrading RubyGems to 1.5.3, since it happens with RubyGems 1.6.0+ and Rails < 2.3.11:
gem update --system 1.5.3
If you had previously downgraded to an even earlier version and want to update to 1.5.3, you might get the following when trying to run that:
Updating RubyGems
ERROR: While executing gem ... (RuntimeError)
No gem names are allowed with the --system option
If you get that error, then update, so that it lets you specify the version, and then downgrade again:
gem update --system
gem update --system 1.5.3
This is an incompatibility between Rails 2.3.8 and recent versions of RubyGems. Upgrade to the latest 2.3 version (2.3.11 as of today).
You can also likely get around this issue by requiring 'thread' in your application as such:
require 'thread'
As per the RubyGems 1.6.0 release notes.
If you want to keep your version same like rails will be 2.3.8 and gem version will be latest. You can use this solution Latest gem with Rails2.x. in this some changes in boot.rb file and environment.rb file.
require 'thread' in boot.rb file at the top.
and in environment.rb file add the following code above the initializer block.
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.3.7')
module Rails
class GemDependency
def requirement
r = super
(r == Gem::Requirement.default) ? nil : r
end
end
end
end
I have faced this problem in many occassions when I try to start an old rails 2.3.5 project after having worked with rails 3>. In my case to solve the problem, I must do a rubygems update to version 1.4.2, this is:
sudo gem update --system 1.4.2
If you're using Radiant CMS, simply add
require 'thread'
to the top of config/boot.rb.
(Kudos to Aaron's and nathanvda's responses.)
As mentioned this occurs when using RubyGems 1.6.0 with Ruby on Rails version earlier than version 3. My app is using Ruby on Rails 2.3.3 vendored into the /vendor of the project.
No doubt an upgrade of Ruby on Rails to a newer 2.3.X version may also fix this issue. However, this problem prevents you running Rake to unvendor Ruby on Rails and upgrade it.
Adding require 'thread' to the top of environment.rb did not fix the issue for me. Adding require 'thread' to /vendor/rails/activesupport/lib/active_support.rb did fix the problem.
Try updating your Ruby on Rails version to v3.0.5:
gem install rails --version 3.0.5
or v2.3.11:
gem install rails --version 2.3.11
If this isn't a new project you'll have to upgrade your application accordingly. If it was a new project, just delete the directory you created it in and create a new project again.
update the rubygems
gem update --system
I'm posting my solution for the other sleep-deprived souls out there:
If you're using RVM, double-check that you're in the correct folder, using the correct ruby version and gemset. I had an array of terminal tabs open, and one of them was in a different directory. typing "rails console" produced the error because my default rails distro is 2.3.x.
I noticed the error on my part, cd'd to the correct directory, and my .rvmrc file did the rest.
RVM is not like Git. In git, changing branches in one shell changes it everywhere. It's literally rewriting the files in question. RVM, on the other hand, is just setting shell variables, and must be set for each new shell you open.
In case you're not familiar with .rvmrc, you can put a file with that name in any directory, and rvm will pick it up and use the version/gemset specified therein, whenever you change to that directory. Here's a sample .rvmrc file:
rvm use 1.9.2#turtles
This will switch to the latest version of ruby 1.9.2 in your RVM collection, using the gemset "turtles". Now you can open up a hundred tabs in Terminal (as I end up doing) and never worry about the ruby version it's pointing to.

Rails performance tests "rake test:benchmark" and "rake test:profile" give me errors

I'm trying to run a blank default performance test with Ruby 1.9 and Rails 2.3.5 and I just can't get it to work! What am I missing here???
rails testapp
cd testapp
script/generate scaffold User name:string
rake db:migrate
rake test:benchmark
-
/usr/local/bin/ruby19 -I"lib:test" "/usr/local/lib/ruby19/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/performance/browsing_test.rb" -- --benchmark
Loaded suite /usr/local/lib/ruby19/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
/usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in `rescue in const_missing': uninitialized constant BrowsingTest::STARTED (NameError)
from /usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:94:in `const_missing'
from /usr/local/lib/ruby19/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/testing/performance.rb:38:in `run'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:415:in `block (2 levels) in run_test_suites'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:409:in `each'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:409:in `block in run_test_suites'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:408:in `each'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:408:in `run_test_suites'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:388:in `run'
from /usr/local/lib/ruby19/1.9.1/minitest/unit.rb:329:in `block in autorun'
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby19 -I"lib:test" "/usr/l...]
OK, the problem is that ruby 1.8 used Test::Unit as its default testing library. In ruby 1.9 that got changed to MiniTest.
Versions of ActiveSupport prior to 3.1.0 assumed Test::Unit. It looks like it has been addressed in 3.1.0 and later. If you're using rails 3.0.9 though, it has a dependency on activesupport 3.0.9, so you can't ask for later versions in your Gemfile.
Found this via Google. Apparently, the Test::Unit library is still available, but as a gem named 'test-unit'.
So in my Gemfile at the top before the rails gem, I put:
gem 'test-unit', '~> 2.3.0'
Then I ran rake test:benchmark and it worked!
I think it's a bug. I am able to run the code with ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]. Under Ruby 1.9.1, I get an exception like the one you describe.
When it reaches ActiveSupport::Testing::Performance#run (in rails) it causes an exception at the line yield(self.class::STARTED, name) where it tries to find the constant ::START. Ruby Prof has a similar method too, under RubyProf::Test#run.
I don't know who's at fault here.
See this.
For a patch, see here.

Resources