재 지정을 강타 할 friendly_id을 사용하고 있습니다 저장 버튼은 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
에 전달하여 여기를 조종 할 여지가있는 것처럼 보입니다.
, BTW 제안 무엇 @corneliusk 할 수있는 또 다른 방법은 다음과 같습니다
render { json: {url: post_path(post.slug)} }
어느 쪽이든는 응답 본문은 mercury:saved
콜백 함수에 인수로 전달됩니다.
위의 인수 [1] .url을 의미한다고 생각합니다. – jordanpg
@jordanpg, 당신이'render : json => {: url => post_path (post.slug)}'를 의미한다고 생각합니다. – corneliusk
@ awendt-이 답변은 사람들에게 유용 할 것 같아요, 받아 들일 수 있다고 생각하세요? – corneliusk