0
我想更新一些带HTML5 contenteditable选项的stroy的情节。这里是代码。需要更新Rails模型的Ajax调用HTML5 contenteditable,而不是它的创建新记录
查看文件#,其中多条曲线可以修改
<div id="editable" contenteditable="true">
<%= simple_format p.description %>
</div>
AJAX#
$(function(){
var contents = $("#editable").html();
$('#editable').blur(function() {
if (contents!=$(this).html()){
alert('Handler for .change() called.');
contents = $(this).html();
autoSavePost();
}
})
});
function autoSavePost(){
var data = {id: parseInt($("#plot_id").text()), tale_id: parseInt($("#tale").text()) ,description: $("#editable").html(), user_id: parseInt($("#user").text())};
console.log(data);
$.ajax({
type: "POST",
url: "/plots",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(data),
success: function(){
$("#success-indicate").fadeIn().delay(4000).fadeOut();
}
});
// setTimeout(autoSavePost, 6000);
}
routes文件#
resources :plots do
member do
post 'update'
end
end
控制器文件#
def update
respond_to do |format|
if @plot.update(params[:description])
format.html { redirect_to plots_path, notice: 'Plot was successfully updated.' }
format.json { render:@plot }
format.js
else
format.html { render action: 'edit' }
format.json { render json: @plot.errors, status: :unprocessable_entity }
end
end
end
我在问专家的帮助。会很感激
现在改变URL格局研究后,其更新为“阴谋/ ID”和类型为“PUT” – sukanta 2014-10-14 23:05:59