ここで回答されているように、現在のページを更新せずに新しいレコードを作成するフォームを送信するために ajax を使用しています: https://stackoverflow.com/a/6723501/1162836
これはその答えからのajaxです:
$('form').submit(function() {
var valuesToSubmit = $(this).serialize();
$.ajax({
type: 'POST',
url: $(this).attr('action'), //sumbits it to the given url of the form
data: valuesToSubmit,
dataType: "JSON" // you want a difference between normal and ajax-calls, and json is standard
}).success(function(json){
//act on result.
});
return false; // prevents normal behaviour
});
新しく作成されたレコードの ID を取得するにはどうすればよいですか?