Rails:Ajax本地工作正常,但在nginx服务器中是404

时间:2013-08-26 12:35:12

标签: ruby-on-rails ruby ajax nginx

在js文件中:

function jqShowResourcesSelection( elem, select_id )
{
    if (elem.checked){
        $("#" + select_id).attr("disabled","disabled");
        $.ajax({
            url: '/testbeds/resources_selection',
            type: 'POST',
            dataType : 'script',
            data: {"configuration_id": $("#" + select_id).val()},
            success: function() {
                addFilter();
            }
        });
    }
    else {
        $("#testbed_configuration_id").attr("disabled", false);
        $("#ResourcesSelection").html('');
    }
}

在routes.rb

ResourceManager::Application.routes.draw do
  resources :testbeds do
    collection do
      post :resources_selection
    end
  end
  resources :resources
  resources :configurations

  ...................

  root :to => 'configurations#index'

end

它在我的本地机器,开发和生产环境中都能正常工作。但是在服务器nginx中,触发js函数后,chrome控制台将显示:

POST http://example.com/testbeds/resources_selection 404 (Not Found)

我也试过“发布”到“获取”:

function jqShowResourcesSelection( elem, select_id )
{
    if (elem.checked){
        $("#" + select_id).attr("disabled","disabled");
        $.ajax({
            url: '/testbeds/resources_selection.js',
            type: 'GET',
            data: {"configuration_id": $("#" + select_id).val()},
            success: function() {
                addFilter();
            }
        });
    }
    else {
        $("#testbed_configuration_id").attr("disabled", false);
        $("#ResourcesSelection").html('');
    }
}

routes.rb中:

ResourceManager::Application.routes.draw do
  resources :testbeds do
    collection do
      get :resources_selection
    end
  end
 ...........................

end

无论是开发还是生产环境,它在本地也能正常工作。但在我选中复选框后,服务器中仍然是404。

和ngnix配置如下:

http {
    passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.18;
    passenger_ruby /usr/local/bin/ruby;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen 80;
        server_name cth-infra-07.datadomain.com 10.110.131.4 localhost;
        root /var/www/webapps/;
        rack_env production;
        passenger_enabled on;
        passenger_base_uri /resource_manager;
        passenger_base_uri /request_handler;
        passenger_base_uri /scheduler;
        passenger_base_uri /resque;
        passenger_base_uri /central_server;
    }

有人可以帮我吗?感谢。

0 个答案:

没有答案