7

我尝试将应用程序从 3.2 升级到 rails 4。我认为目前所有的 gem 冲突都已解决,但后来我知道它可能会再次发生。

当我尝试“捆绑 exec rails s”并在浏览器中打开应用程序时,转到应用程序主页索引,它给了我这个错误:

IOError(未打开读取)

有人可以帮忙吗?太感谢了。

这是我使用的宝石列表:

gem 'rails', '4.0.1'

gem 'sass-rails',   '~> 4.0.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'

gem 'jquery-rails'

gem 'jbuilder', '~> 1.2'
# add these gems to help with the transition:
gem 'protected_attributes'
gem 'rails-observers'
gem 'actionpack-page_caching'
gem 'actionpack-action_caching'
gem "activerecord-session_store"

这是控制台的日志消息:

Started GET "/" for 127.0.0.1 at 2013-11-06 20:16:27 +1100
Processing by HomeController#index as HTML
  PCategory Load (0.5ms)  SELECT "p_categories".* FROM "p_categories"
  Rendered home/index.html.erb within layouts/application (4.1ms)
Completed 500 Internal Server Error in 15ms

IOError (not opened for reading):
  activesupport (4.0.1) lib/active_support/json/encoding.rb:256:in `each'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:256:in `to_a'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:256:in `as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:58:in `block in as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:81:in 'check_for_circular_references'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:57:in `as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:296:in `block in as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:296:in `each'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:296:in `map'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:296:in `as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:58:in `block in as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:81:in g`check_for_circular_references'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:57:in `as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:296:in `block in as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:296:in `each'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:296:in `map'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:296:in `as_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:50:in `block in encode'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:81:in `check_for_circular_references'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:49:in `encode'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:306:in `block in encode_json'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:306:in `each'
  activesupport (4.0.1) lib/active_support/json/encoding.rb:306:in `map'
4

3 回答 3

4

原来 GEM 冲突是我遇到类似问题的罪魁祸首。我解决了使用 Rails 的间接相关问题的代码问题。请看下文,希望对你有所帮助。

#fix for JSON gem/activesupport bug. More info: http://stackoverflow.com/questions/683989/how-do-you-deal-with-the-conflict-between-activesupportjson-and-the-json-gem
if defined?(ActiveSupport::JSON)
  [Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass|
    klass.class_eval do
      def to_json(*args)
        super(args)
      end
      def as_json(*args)
        super(args)
      end
    end
  end
end
于 2013-12-09T14:05:43.130 回答
1

我使用 ActiveModel Serializers gem 体验了这一点。我将 ActiveModel Serializers 从 0.8.1 升级到 0.9,之后它运行良好。

于 2014-11-26T13:13:08.067 回答
1

我自己最近遇到了这个问题。经过几天的反复试验,我最终注释掉了一组开发组 gem(幸运的猜测),然后一个一个地重新启用每个 gem,用每个新启用的 gem 重建我的 gem 集。罪魁祸首原来是MetaRequest gem 和它的依赖,rack-contrib(它做一些 JSONP 工作)。

所以这就是我的建议:

  1. 清空您的宝石集(rvm gemset empty如果您使用的是 rvm)
  2. 将您的 Gemfile.lock 文件重命名为 Gemfile.lock.OLD(这可能不是必需的,但列出以防万一)
  3. 在您的 Gemfile 中,注释掉您怀疑处理请求或执行任何 JSON 工作的所有 gem
  4. 运行bundle install以在没有注释掉的宝石的情况下重建您的宝石集
  5. 重新启动您的服务器。如果您仍然收到 IOError,请重复步骤 1-5。否则,继续执行步骤 6。
  6. 取消注释您注释掉的宝石之一
  7. 运行bundle install以安装 gem 及其依赖项
  8. 重新启动您的服务器。如果您没有遇到 IOError,请重复步骤 6-8。否则,您上次重新启用的 gem 就是原因。
于 2013-11-19T19:57:49.767 回答