Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
Created June 19, 2012 07:35
Show Gist options
  • Save jhjguxin/2952820 to your computer and use it in GitHub Desktop.
Save jhjguxin/2952820 to your computer and use it in GitHub Desktop.
Kindeditor ajax post for Ruby on Rails
_form.html.erb
<%= f.input :body, :width => 850, :height => 500 %>
refresh.js.erb
$("#edit_<%= dom_id @knowledge %>").replaceWith("<%= render 'refresh_form'%>");
$("#new_knowledge").replaceWith("<%= render 'refresh_form'%>");
var editor = KindEditor.create(
'textarea[id="knowledge_body"]',
{
width : '850px',
height: '500px',
uploadJson: '/kindeditor/upload',
fileManagerJson: '/kindeditor/filemanager'
}
);
$(document).ready(function(){
var editor = KindEditor.create(
'textarea[id="knowledge_body"]',
{
width : '850px',
height: '500px',
uploadJson: '/kindeditor/upload',
fileManagerJson: '/kindeditor/filemanager'
}
);
$("input").click(function(){
editor.sync('knowledge_body');
// 同步数据后可以直接取得textarea的value
body = document.getElementById('knowledge_body').value; // 原生API
$("#knowledge_body").val(body);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment