根据 ruby.railstutorial.org 升级到 rails 4 后无法加载 railtie [英] cannot load railtie after upgrade to rails 4 per ruby.railstutorial.org
问题描述
操作系统是 Ubuntu 12.04,64 位.
OS is Ubuntu 12.04, 64 bit.
Rails 新手.Ruby 相对较新.遵循 ruby.railstutorial.org 教程,第 3 章.
New to rails. Relatively new to Ruby. Following the ruby.railstutorial.org tutorial, chapter 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 服务器
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>'
我确实从 Rails: 找不到 railties 中得到了一些想法,概述如下,但尚未找到解决方法.
I did get some ideas from Rails: Could not find railties, outlined below, but haven't yet found a fix.
这是详细信息.
昨天(在我的浏览器中)第 3 章的 Gemfile 如下.一切正常.
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
今天早上教程中的 Gemfiles 使用的是 ruby 2.0.0 和 rails 4.0.0.rc1.我想让这个设置正常工作,所以我与更新的教程没有冲突.新建 Gemfile 如下.
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
首先,我将 Gemfile 中的 ruby 版本更改为 ruby '1.9.2',因为这是我正在运行的,并且认为我在更新包时出错.我没有做笔记.
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.
然后在 Gemfile 中将 ruby 版本改回2.0.0",然后:
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
现在我在使用 rails 命令时遇到 cannot load railtie 错误.
Now I'm getting the cannot load railtie error with rails commands.
从 Rails: 找不到 railties,我尝试了以下
$ 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 进行了更新.)
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
还是报错
啊!!!
有什么想法吗?
推荐答案
ActiveResource 是 Rails 2.x 中添加的一种 API,用于支持 XML(以及后来的 JSON)API,以便 Rails 站点可以相互对话".当 RESTful API 的想法进入框架时,这是一个非常热门的话题.随着时间的推移,它变得越来越新奇并且很少维护,因此它被从 Rails 4.x 的核心中提取出来.
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.
在 Rails 4.x 中有两种选择.如果您不打算使用 ActiveResource(如果您是 Rails 的新手并正在编写教程,我认为是这种情况),那么您可以简单地删除或注释掉将其拉入框架的 railtie.打开 'config/application.rb' 并注释掉第七行.
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
如果您想使用 ActiveResource,只需将其添加到项目的 Gemfile 中即可.以前它作为依赖项包含在 rails gem 中;现在,如果您想使用它,您必须明确添加它.
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.
这篇关于根据 ruby.railstutorial.org 升级到 rails 4 后无法加载 railtie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!