views:

97

answers:

2

I have a form I wish to submit via ajax usind the jQuery $.post command.

The form looks like this:

<form action="/wine/merlot/reviews" class="new_review" id="new_review" method="post">

And the jquery call is:

$(document).ready(function() {
  $('#new_review').submit(function() {
    $.post($(this).attr('action'), $(this).serialize(), null, 'script');
    return false;
  });
});

I get the following error on the server:

ActionController::MethodNotAllowed (Only get, put, and delete requests are allowed.):

From what I can tell by digging in with firebugs console the problem is the post is posting to this url:

/wine/merlot instead of /wine/merlot/reviews

I can't for the life of me figure out why this is the case.

A: 

Not sure, but try /wine/merlot/reviews/ instead of /wine/merlot/reviews?

Fiona Holder
+1  A: 

OK. It turns out I'm an idiot. I had another div on the page with the id "new_review" so I guess it was looking at the wrong element. Renamed and everything working now.

KJF