A client with a Rails 2 app that displays games written in Flash is having 
them converted to HTML5/Javascript. The team doing the conversions has no 
problem reading the player's data with a Javascript function like this, 
which I bound to a button click and ran with the Chrome debugging console 
open:


> *function makeGetRequest() {*
> *  var request = new XMLHttpRequest();**  request.open('GET', 
> <...url...>);*
>
> *  // Response handler*
> *  request.onload = function() {*
> *    var text = request.responseText;*
> *    console.log("responseText="+text)**  };*
>
> *  request.send();**}*


I have omitted the code to handle CORS (cross-origin resource sharing), 
which is set in .htaccess on the server and does not seem to be a problem.

The following works in development to push data back to the Rails 2 app:


> *function makePutRequest() {*
> *  var request = new XMLHttpRequest();**  request.open('PUT', 
> <...url...>);*
>
> *  // Response handler*
> *  request.onload = function() {*
> *    var text = request.responseText;*
> *    console.log("responseText="+text)**  };*
>
> *  request.setRequestHeader('Content-type', 'application/json');*
> *  request.send('{"data":"this is updated data player data"}');**}*


but does not work in production. Changing 'PUT' to 'POST' and adding

*  xhr.setRequestHeader('X-HTTP-Method-Override', 'PUT');*


also works in development but not in production.

The Chrome console says:

*XMLHttpRequest cannot load <...url...>. Invalid HTTP status code 405 *


The Rails 2 production log says:


> *Processing ApplicationController#index (for xx.xxx.xx.xxx at 2014-10-22 
> 14:31:28) [OPTIONS]ActionController::MethodNotAllowed (Only get and put 
> requests are allowed.):*


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/routing/recognition_optimisation.rb:64:in
>  
> `recognize_path'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/routing/route_set.rb:442:in
>  
> `recognize'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/routing/route_set.rb:437:in
>  
> `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/dispatcher.rb:87:in
>  
> `dispatch'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/dispatcher.rb:121:in
>  
> `_call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/dispatcher.rb:130:in
>  
> `build_middleware_stack'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/activerecord/lib/active_record/query_cache.rb:29:in
>  
> `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/activerecord/lib/active_record/query_cache.rb:29:in
>  
> `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in
>  
> `cache'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/activerecord/lib/active_record/query_cache.rb:9:in
>  
> `cache'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/activerecord/lib/active_record/query_cache.rb:28:in
>  
> `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in
>  
> `call'  haml (3.0.25) rails/./lib/sass/plugin/rack.rb:41:in `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/string_coercion.rb:25:in
>  
> `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/params_parser.rb:15:in
>  
> `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/session/cookie_store.rb:99:in
>  
> `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/failsafe.rb:26:in
>  
> `call'  
> /opt/ruby-enterprise-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems/rails-31a564b77c73/actionpack/lib/action_controller/dispatcher.rb:106:in
>  
> `call'  passenger (3.0.12) 
> lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'*



It got as far as actionpack, so why is production behaving badly but not 
development? Is Apache/Passenger mangling the request before it gets there? 

The app uses the latest version of Rails 2, ree-1.8.7, and Passenger, 
hosted at RailsPlayground, where it has run without major problems for five 
years.

I'm at a dead-end with Google. Anyone got an idea on what is the problem 
here?

Thanks much, Scott

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to