rails rails_kindeditor

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,必须刷新页面才会生成文本编辑器,否则只生成一个普通的<textarea></textarea>标签
解决的办法有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"

编辑器具体的初始化参数查看http://kindeditor.net/docs/option.html










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值