jQuery.ajax
保存ボタンは単なる呼び出しであるため、サーバー側でのリダイレクトは機能しません。
// page_editor.js
PageEditor.prototype.save = function(callback) {
var data, method, options, url, _ref, _ref1,
_this = this;
url = (_ref = (_ref1 = this.saveUrl) != null ? _ref1 : Mercury.saveUrl) != null ? _ref : this.iframeSrc();
data = this.serialize();
data = {
content: data
};
if (this.options.saveMethod === 'POST') {
method = 'POST';
} else {
method = 'PUT';
data['_method'] = method;
}
Mercury.log('saving', data);
options = {
headers: Mercury.ajaxHeaders(),
type: method,
dataType: this.options.saveDataType,
data: data,
success: function(response) {
Mercury.changes = false;
Mercury.trigger('saved', response);
if (typeof callback === 'function') {
return callback();
}
},
error: function(response) {
Mercury.trigger('save_failed', response);
return Mercury.notify('Mercury was unable to save to the url: %s', url);
}
};
if (this.options.saveStyle !== 'form') {
options['data'] = jQuery.toJSON(data);
options['contentType'] = 'application/json';
}
return jQuery.ajax(url, options);
};
したがって、リダイレクトはsuccess
コールバックに送信されますが、成功した AJAX 要求と同様に、ページは実際には再レンダリングされません。著者は、この関数のオーバーライドについてここで説明しています。また、コールバック関数を に渡すことで、ここで操作する余地があるようにも見えますsave
。
ところで、@corneliuskが提案することを行う別の方法は次のとおりです。
render { json: {url: post_path(post.slug)} }
どちらの方法でも、応答本文はコールバック内の関数に引数として渡されmercury:saved
ます。