在每个ruby.railstutorial.org升级到rails 4后无法加载railtie [英] cannot load railtie after upgrade to rails 4 per ruby.railstutorial.org

查看:136
本文介绍了在每个ruby.railstutorial.org升级到rails 4后无法加载railtie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OS是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 server

  user @ machine:〜/ bin / railslearn / sample_app $ rails server 
/home/paul/bin/railslearn/sample_app/config/application.rb:7:in`require':无法加载这样的文件 - active_resource / railtie(LoadError)
from / home / paul / bin / railslearn / sample_app / config / application.rb:7:在< 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:'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:在'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:在< top(required)>'
脚本/导轨中:6:在`热曲ire'
from script / rails:6:in< main>'

I从 Rails:无法找到railties ,下面概述了一些想法,

以下是详细信息。



昨天(在我的浏览器中)第一章的Gemfile 3如下。一切正常。

  $ 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'
结束

#默认情况下,Gems仅用于资产并且不需要
#。
group:assets do
gem'sass-rails','3.2.5'
gem'coffee-rails','3.2.2'
gem'uglifier',' 1.2.3'
结束

组: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 =>假
#gem'growl','1.0.3'
结束

组:生产do
gem'pg','0.12.2'
结束

今天早上,教程中的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',要求:false
end

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

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


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

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

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

Rails:无法找到railt ,我试过以下内容:

  $ gem uninstall railties 

选择gem卸载:
1. railties-4.0.0.rc1
2. railties-3.2.13
3.所有版本
> 2

您已请求卸载gem:
railties-3.2.13

rails-3.2.13取决于railties(= 3.2.13)
如果你删除这个宝石,这些依赖不会被满足。
Y#卸载railties-3.2.13

仍然出错

  $ gem uninstall rails#卸载rails-3.2.13 
$ gem uninstall railties#还可以卸载railties-4.0.0.rc1
$ rvm重新安装2.0.0
$ rvm 2.0.0 - 默认
$ bundle update#使用Gemfile和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)
sprocket-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#使用Gemfile和ruby 2,rails 4
$ bundle install

仍然出错



ug !!!



有什么想法?

解决方案

ActiveResource是Rails 2.x中添加的一个API,用于支持XML(以及更高版本的JSON)API,以便Rails站点可以相互交谈。当RESTful API的概念进入框架时,这是一个非常热门的话题。随着时间的推移,它变得更加新奇,并且很少被维护,所以它被从Rails 4.x的核心中拉出来。

Rails 4.x有两个选项。如果你不打算使用ActiveResource(如果你是Rails的新手,并且正在编写一个教程,那么我会假设情况是这样的),那么你可以简单地删除或注释掉将它带入框架的railtie。打开'config / application.rb'并注释掉第七行。

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

#选择你想要的框架:
需要active_record / railtie
需要action_controller / railtie
需要action_mailer / railtie
#需要active_resource / railtie< <注释掉这一行

如果你想要使用ActiveResource,然后将其添加到项目的Gemfile。以前它被rails rails包含为依赖;现在如果你想使用它,你必须明确地添加它。


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?

解决方案

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.

这篇关于在每个ruby.railstutorial.org升级到rails 4后无法加载railtie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆