This project is archived and is in readonly mode.

#3211 ✓resolved
Mauricio Eduardo Szabo

Internal Server Error on render :text using procs and ActiveRecord

Reported by Mauricio Eduardo Szabo | September 15th, 2009 @ 08:32 PM

When I try to access any method of any ActiveRecord object on a render :text with procs, WEBrick and Mongrel fails with a server error and the message "You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.include?"

To reproduce the error, try:
$ rails stream $ cd stream $ script/generate scaffold person name:string age:integer $ rake db:migrate

Now, create a person, and substitute the contents of the index method on the controller to:
def index

@people = Person.all

respond_to do |format|
  format.html {
    render :text => Proc.new { |req, resp|
      @people.each do |person|
        resp.write "#{person.name}\n"
      end
    }
  }
  format.xml  { render :xml => @people }
end

end

And try to point your browser to http://localhost:3000/people. Below, is the backtrace I get (in console):
The error occurred while evaluating nil.include?

    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/attribute_methods.rb:142:in `create_time_zone_conversion_attribute?'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/attribute_methods.rb:75:in `define_attribute_methods'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/attribute_methods.rb:71:in `each'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/attribute_methods.rb:71:in `define_attribute_methods'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/attribute_methods.rb:242:in `method_missing'
    /tmp/stream/app/controllers/people_controller.rb:11:in `index'
    /tmp/stream/app/controllers/people_controller.rb:10:in `each'
    /tmp/stream/app/controllers/people_controller.rb:10:in `index'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/response.rb:153:in `call'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/response.rb:153:in `each'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb:58:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb:13:in `run'
    /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111
    /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages