1、安装 gem 'rails_kindeditor'
2、运行rails generate rails_kindeditor:install
identical config/initializers/rails_kindeditor.rb
insert app/assets/javascripts/application.js
3、使用基本用法
<%= kindeditor_tag :content, 'default content value' %> # or <%= kindeditor_tag :content, 'default content value', :width => 800, :height => 300 %> # or <%= kindeditor_tag :content, 'default content value', :allowFileManager => false %>与simple_form集成,form_for中的用法与其类似
<%=simple_form_for @article do |f| %> ... <%= f.kindeditor :content %> # or <%= f.kindeditor :content, :width => 800, :height => 300 %> # or <%= f.kindeditor :content, :allowFileManager => false %> ... <% end %> 三种写法:
kindeditor_tag :content, 'default content value', :simple_mode => true f.kindeditor :content, :simple_mode => true f.input :content, :as => :kindeditor, :input_html => { :simple_mode => true } 在turbolinks中的用法: rails框架中默认使用turbolinks插件,但是如果在使用turbolinks插件的情况下使用kindeditor,必须刷新页面才会生成文本编辑器,否则只生成一个普通的标签 解决的办法有2种 1.在页面关闭turbolinks插件
<%= link_to 'Edit', edit_article_path(article), 'data-no-turbolink' => true %> 2.在turbolinks载入完毕后手动加载kindeditor,不过所有参数都要设置,而且需要知道并设定textarea的id
$(document).on 'page:load', -> if $('#article_content').length > 0 KindEditor.create '#article_content', "width":"100%", "height":300, "allowFileManager":true, "uploadJson":"/kindeditor/upload", "fileManagerJson":"/kindeditor/filemanager"