Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade to Rails 4 got IOError (not opened for reading)

I try to upgrade an app from 3.2 to rails 4. i think all the gems conflicts have been solved at the moment though later i know it might happen again.

While i try to "bundle exec rails s" and open the app in browser go the app home index, it gives me this error:

IOError (not opened for reading)

Could anyone help with this? Thank you so much.

here is the gem list i used:

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"

And here is the log message for console:

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'
like image 497
LPing Avatar asked Nov 06 '13 09:11

LPing


3 Answers

Turns out a GEM conflict was the culprit of a similar issue that I had. I fixed the problem with the code from an indirectly related question that used Rails instead. Please see below, I hope this helps you.

#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
like image 101
Phil Hudson Avatar answered Nov 04 '22 13:11

Phil Hudson


I experienced this issue recently myself. After a few days of trial and error, I eventually commented out a set of development group gems (lucky guess), then re-enabled each gem one by one, rebuilding my gem set with each newly enabled gem. The culprit turned out to be the MetaRequest gem and its dependency, rack-contrib (which does some JSONP work).

So here's what I suggest:

  1. Empty your gem set (rvm gemset empty if you're using rvm)
  2. Rename your Gemfile.lock file to Gemfile.lock.OLD (this may not be necessary, but listed just in case)
  3. In your Gemfile, comment out any gems that you suspect handle requests or do any JSON work
  4. Run bundle install to rebuild your gem set without the commented-out gems
  5. Restart your server. If you still receive the IOError, repeat steps 1-5. Otherwise, proceed to step 6.
  6. Un-comment one of the gems you commented out
  7. Run bundle install to install the gem and its dependencies
  8. Restart your server. If you don't encounter the IOError, repeat steps 6-8. Otherwise, the gem you re-enabled last is the cause.
like image 40
user3006381 Avatar answered Nov 04 '22 12:11

user3006381


I experienced this with ActiveModel Serializers gem. I upgraded ActiveModel Serializers from 0.8.1 to 0.9 and it worked fine after that.

like image 23
Tyrone Wilson Avatar answered Nov 04 '22 12:11

Tyrone Wilson