<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>&lt;p&gt;Earlier this afternoon, I was debugging an ajax call that consistently resulted in an error, but only in IE.&amp;nbsp; Checking the log file, I found this:&lt;/p&gt;
&lt;pre class="terminal"&gt;Processing ApplicationController#index (for 192.168.1.108 at 2009-10-27 14:37:03) [GET]&lt;br /&gt;  Session ID: ddde16cf83baca85a81e9fb0772c2844&lt;br /&gt;  Parameters: {"format"=&amp;gt;"js", "page"=&amp;gt;"1"}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ActionController::MethodNotAllowed (Only get, head, post, put, and delete requests are allowed.):&lt;br /&gt;    /vendor/rails/actionpack/lib/action_controller/routing/recognition_optimisation.rb:65:in `recognize_path'&lt;br /&gt;    /vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:384:in `recognize'&lt;br /&gt;    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:154:in `handle_request'&lt;br /&gt;    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:107:in `dispatch'&lt;br /&gt;    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in `synchronize'&lt;br /&gt;    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in `dispatch'&lt;br /&gt;    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'&lt;br /&gt;    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:35:in `dispatch'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/request_handler.rb:50:in `process_request'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:378:in `start_request_handler'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:336:in `handle_spawn_application'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/utils.rb:183:in `safe_fork'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:334:in `handle_spawn_application'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `__send__'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:163:in `start'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/railz/application_spawner.rb:213:in `start'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `__send__'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'&lt;br /&gt;    /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/bin/passenger-spawn-server:61&lt;br /&gt;&lt;br /&gt;Rendering /Users/brent/Intridea/project/vendor/rails/actionpack/lib/action_controller/templates/rescues/layout.erb (method_not_allowed)&lt;/pre&gt;
&lt;p&gt;WTF?&amp;nbsp; That told me a whole lotta nothing.&lt;/p&gt;
&lt;p&gt;First of all, it was blowing up before it even got into the application code, which was was strange because it worked just fine in Firefox, Safari, etc.&amp;nbsp; Second, I checked the response body and it was returning html.&amp;nbsp; Html?&amp;nbsp; The format is clearly specified as "js" in the request parameters.&amp;nbsp; Double-checking the controller code, there was definitely a respond_to block with format.js, so why was it returning html?&lt;/p&gt;
&lt;p&gt;I showed this to one of my coworkers and he asked if I had tried switching the format calls in the respond_to block.&amp;nbsp; There were two, one for html and one for javascript.&amp;nbsp; I switched them up, and put the format.js first.&amp;nbsp; I reloaded the page, and what do you know, it worked!&amp;nbsp; No error.&amp;nbsp; Again, wtf?&amp;nbsp; He told me that this same bug had kicked his ass on a previous project.&lt;/p&gt;
&lt;p&gt;Aparently, IE7 isn't specific about what sort of response it expects in the accept header.&amp;nbsp; This causes Rails to merely return the first format that it comes to.&amp;nbsp; In my case, the html.&lt;/p&gt;
&lt;p&gt;So if you're not seeing the format that you're expecting when testing with IE7, try reordering the format calls in the respond_to block.&lt;/p&gt;</body>
  <created-at type="datetime">2009-10-28T01:26:06Z</created-at>
  <description>IE7 doesn't explicitly specify what format it expects in the accept header.  This causes Rails to render the first format in the respond_to block.  </description>
  <id type="integer">37</id>
  <keywords>rails, respond_to, ie, ie7, format, bug</keywords>
  <published type="boolean">true</published>
  <slug>ie7-accept-header-and-rails-respon-to-bug</slug>
  <title>IE7's Accept Header And Rails respond_to Bug</title>
  <updated-at type="datetime">2009-10-28T01:26:30Z</updated-at>
</post>
