I’m trying to send data to my Ruby on Rails application via an AJAX POST request.
This works fine on the index page where it just accepts the POST request and takes the parameter for usage like params[:MyParam], however when trying to do the exact same thing in my show action, I get the error:
No route matches [POST]
I’m sending the POST request like so:
<% if !params[:recData] %>
var PostDone = false;
<% end %>
$(document).ready(function() {
$.post(document.URL, { recData: "POST REQUEST!" }, function(response) {
if(PostDone == false) {
document.write(response);
PostDone = true;
}
});
});
I’m kind of new to AJAX and Rails, so a helping hand would be much appreciated.
Ok first of all if you read this you know that
resources :productsadds following routealso routes are matched from the top so since you have
each time you have POST request to the
'/products'first route defined withresources :productsis matchedshowaction works because it is also defined withresources :productsbut only for GET methodnow workarounds
change order to
or use
:exceptin both cases your
createaction will newer be matched