Upgrade to Rails 4 received IOError (not open for reading)

I am trying to update the application from 3.2 to rails 4. I think that all conflicts of gems were resolved at that moment, although later I know that this can happen again.

While I try to β€œbind exec rails s” and open the application in the browser, turn on the home application index, it gives me this error:

IOError (not open for reading)

Can anyone help with this? Thank you very much.

Here is the list of gems that 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 the 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' 
+7
ruby-on-rails-4
source share
3 answers

It turns out that the GEM conflict was the culprit of a similar problem that I had. I fixed the code issue from an indirectly related question that Rails used. 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 
+4
source share

I recently survived this question. After several days of trial and error, I finally commented on the set of gems of the development group (a good guess), and then turned on each gem again one by one, restoring the set of gems with each newly turned on gem. The culprit turned out to be the gem of MetaRequest and its addiction, rack-contrib (which does some JSONP work).

So here is what I suggest:

  • Clean your gem set ( rvm gemset empty if you use rvm)
  • Rename the file Gemfile.lock to Gemfile.lock.OLD (this may be optional, but just in case)
  • In your Gemfile, comment out any gems that you suspect of processing requests or are doing some JSON work.
  • Run bundle install to rebuild the gem set without commented out gems.
  • Reboot the server. If you still get an IOError, repeat steps 1-5. Otherwise, go to step 6.
  • Do not comment on one of the stones you marked.
  • Run bundle install to install the gem and its dependencies
  • Reboot the server. If you do not encounter an IOError, repeat steps 6-8. Otherwise, the reason you reactivated is the reason.
+1
source share

I tested this with the Serializers shortcut from ActiveModel. I updated ActiveModel serializers from 0.8.1 to 0.9, and after that it worked fine.

+1
source share

All Articles