If you have a Type model, with corresponding types_controller, and you're using REST patterns, when you send a POST or PUT request with a valid XML formatted Type resource, Rails will crash with:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.update
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/request.rb:13:in `parameters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/request.rb:20:in `method'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1333:in `extract_request_environment'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1282:in `recognize'
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:40:in `dispatch'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
...
Supose you have types table like that:
class CreateTypes < ActiveRecord::Migration
def self.up
create_table :types do |t|
t.column :description, :string
t.column :created_at, :datetime
t.column :updated_at, :datetime
end
end
def self.down
drop_table :types
end
end
the error occurs when you try to POST or PUT a valid Type in xml format, like that:
<?xml version="1.0" encoding="UTF-8"?>
<type>
<created-at type="datetime">2007-08-01T10:09:32Z</created-at>
<description>TYPE POR API</description>
<id type="integer">18</id>
<updated-at type="datetime">2007-08-06T22:01:46Z</updated-at>
</type>
The error doesn't occur when you're using standard HTTP POST or PUT, only with XML.
I think the problem is in xml_simple and "type" as the root node name, if you change it to "ttype", Rails runs as expected.
Sorry, but i'm not expert enought to solve the problem myself!
Isaac.