重定向保存按鈕只是一個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請求一樣。作者討論重寫這個非常功能here。它也看起來像通過回調函數save
可能有一些機動。
順便說一句,另一種方法做什麼建議是@corneliusk:
render { json: {url: post_path(post.slug)} }
無論哪種方式,響應體被作爲參數傳遞給在mercury:saved
回調函數傳遞。
我想你的意思是'參數[1] .url'上面。 – jordanpg 2013-02-03 06:04:38
@jordanpg,我想你的意思是'render:json => {:url => post_path(post.slug)}' – corneliusk 2013-02-04 15:24:10
@ awendt-似乎這個答案對人有用,你認爲你能接受嗎? – corneliusk 2014-02-10 18:43:35