Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

rubygems - cannot load railtie after upgrade to rails 4 per ruby.railstutorial.org

OS is Ubuntu 12.04, 64 bit.

New to rails. Relatively new to Ruby. Following the ruby.railstutorial.org tutorial, chapter 3.

The tutorial has been updated to use ruby 2.0.0 and Rails 4.0.0.rc1. Previously the gemfile was specifying Rails 3.2.13 and not specifying Ruby version. After moving to the latest Gemfile in the tutorial, ruby 2.0.0 and Rails 4.0.0.rc1, I'm getting the following error when running rails commands. Example here is rails server

    user@machine:~/bin/railslearn/sample_app$ rails server
/home/paul/bin/railslearn/sample_app/config/application.rb:7:in `require': cannot load such file -- active_resource/railtie (LoadError)
    from /home/paul/bin/railslearn/sample_app/config/application.rb:7:in `<top (required)>'
    from /home/paul/.rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:78:in `require'
    from /home/paul/.rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:78:in `block in <top (required)>'
    from /home/paul/.rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `tap'
    from /home/paul/.rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I did get some ideas from Rails: Could not find railties, outlined below, but haven't yet found a fix.

Here's the details.

Yesterday (in my browser) the Gemfile for Chapter 3 was as follows. Everything worked fine.

$ cat Gemfile
source 'https://rubygems.org'

gem 'rails', '3.2.13'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'jquery-rails', '2.0.2'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.11.0'
  # gem 'guard-rspec', '1.2.1'
  # gem 'guard-spork', '1.2.0'  
  # gem 'childprocess', '0.3.6'
  # gem 'spork', '0.9.2'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '4.1.0'
  gem 'cucumber-rails', '1.2.1', :require => false
  gem 'database_cleaner', '0.7.0'
  # gem 'launchy', '2.1.0'
  # gem 'rb-fsevent', '0.9.1', :require => false
  # gem 'growl', '1.0.3'
end

group :production do
  gem 'pg', '0.12.2'
end

This morning the Gemfiles in the tutorial are using ruby 2.0.0 and rails 4.0.0.rc1. I'd like to get this setup working, so I don't have conflicts with the updated tutorial. New Gemfile is as follows.

$ cat Gemfile
source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '4.0.0.rc1'

group :development, :test do
  gem 'sqlite3', '1.3.7'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.0.0'
  gem 'capybara', '2.1.0'
end

gem 'sass-rails', '4.0.0.rc1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
end

First I changed the ruby version in the Gemfile to ruby '1.9.2' because that's what I was running, and think I had an error with bundle update. I didn't take notes.

Then changed the ruby version back to '2.0.0' in the Gemfile and:

$ rvm install 2.0.0
$ rvm use 2.0.0 --default
$ bundle update
$ bundle install

Now I'm getting the cannot load railtie error with rails commands.

From Rails: Could not find railties, I tried the following

$ gem uninstall railties

Select gem to uninstall:
 1. railties-4.0.0.rc1
 2. railties-3.2.13
 3. All versions
> 2

You have requested to uninstall the gem:
    railties-3.2.13

rails-3.2.13 depends on railties (= 3.2.13)
If you remove this gem, these dependencies will not be met.
Y # uninstall railties-3.2.13

still getting the error

$ gem uninstall rails # to uninstall rails-3.2.13
$ gem uninstall railties # to also uninstall railties-4.0.0.rc1
$ rvm reinstall 2.0.0
$ rvm 2.0.0 --default
$ bundle update # using the Gemfile with ruby 2, rails 4
$ bundle install

$ gem list | grep rail
coffee-rails (4.0.0)
jquery-rails (2.2.1)
rails (4.0.0.rc1)
railties (4.0.0.rc1)
rspec-rails (2.13.1)
sass-rails (4.0.0.rc1)
sprockets-rails (2.0.0.rc4)

still getting the error

Going back through the original setup from the tutorial in chapter one (now updated for ruby 2, rails 4.)

$ rvm use 2.0.0@railstutorial_rails_4_0 --create --default
$ gem update --system 2.0.0
$ gem install rails --version 4.0.0.rc1 --no-ri --no-rdoc
$ bundle update # using Gemfile with ruby 2, rails 4
$ bundle install

still getting the error

ug!!!

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ActiveResource was an API added in Rails 2.x to support an XML (and later JSON) API so that Rails sites could "talk" to one another. It was a very hot topic when the idea of RESTful APIs made its way into the framework. Over time it became more of a novelty and infrequently maintained so it was pulled from the core in Rails 4.x.

You have two options at Rails 4.x. If you did not intend to use ActiveResource (I'd assume this is the case if you're new to Rails and working on a tutorial) then you can simply remove or comment out the railtie that's pulling it into the framework. Open up 'config/application.rb' and comment out the seventh line.

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "active_resource/railtie"    <--- comment out this line

If you WANT to use ActiveResource, then just add it to the Gemfile for the project. Previously it was included by the rails gem as a dependency; now you'll have to add it explicitly if you want to use it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...