Monday, 26 August 2013

Rails: Ajax local works fine, but 404 in nginx server

Rails: Ajax local works fine, but 404 in nginx server

in the js file :
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('');
}
}
In 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
It works fine in my local machine, both development and production
environment. But in the server, nginx, after trigger the js function, the
chrome console will show:
POST http://xxxx.com/testbeds/resources_selection 404 (Not Found)
I also tried the "post" to "get":
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
It also works fine in local no matter development or production
environment. But still 404 in the server after I checked the checkbox.
Can some one help me about it ? Thanks.

No comments:

Post a Comment