升级到rails4后无法加载rails4



操作系统为Ubuntu 12.04, 64位。

rails新功能。对Ruby来说相对较新。遵循ruby.railstutorial.org教程,第3章。

本教程已更新为使用ruby 2.0.0和Rails 4.0.0.rc1。以前gemfile指定的是Rails 3.2.13而不是Ruby版本。在转移到教程中最新的Gemfile之后,ruby 2.0.0和Rails 4.0.0。rc1,当运行rails命令时,我得到以下错误。这里的例子是rails服务器

    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>'

我确实从Rails得到了一些想法:无法找到railties,概述如下,但尚未找到修复。

详情如下。

昨天(在我的浏览器中)第3章的Gemfile如下。一切正常
$ 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

今天早上教程中的Gemfiles使用ruby 2.0.0和rails 4.0.0.rc1。我想让这个设置工作,所以我没有冲突与更新的教程。新建的Gemfile如下:

$ 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

首先,我将Gemfile中的ruby版本更改为ruby '1.9.2',因为这是我正在运行的,并且认为我在bundle更新时出现了错误。我没有做笔记。

然后在Gemfile中将ruby版本改回'2.0.0'并且:

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

现在我得到不能加载railtie错误与rails命令。

From Rails: Could not find railties, I tried如下

$ 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

仍然得到错误

$ 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)

仍然得到错误

回到第一章教程的原始设置(现在更新为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

仍然得到错误

ug ! !

任何想法?

ActiveResource是Rails 2中添加的API。x来支持XML(以及后来的JSON) API,以便Rails站点可以彼此"对话"。当RESTful api的概念进入框架时,这是一个非常热门的话题。随着时间的推移,它变得越来越新奇,很少被维护,所以它在Rails 4.x中被从核心中拉出来。

在Rails 4.x中有两个选项。如果您不打算使用ActiveResource(我假设如果您是Rails新手并且正在制作教程就是这种情况),那么您可以简单地删除或注释掉将其拉入框架的railtie。打开"config/application"。b',并注释掉第七行。

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

如果你想使用ActiveResource,那么只需将它添加到项目的Gemfile中。以前它是作为一个依赖项包含在rails gem中;现在,如果你想使用它,你必须明确地添加它。

'activeresource'是Rails 4中的一个独立gem

我也有同样的错误。我所做的是:在Gemfile中,我更改了rails的版本:gem 'rails', '4.2.0'然后在命令行中执行如下命令:bundle install。要查看可用的生成器,请在CLI中输入rails grails generate

相关内容

  • 没有找到相关文章

最新更新