rails上使用rich editor kindeditor和ckeditor对比记录

rails下使用rich editor kindeditor和ckeditor对比记录
本文原来是介绍ckeditor的,但后来ckeditor被我弃用。原因是我找到了更好的rich editor,那就是kindeditor。
kindeditor配置安装都简单,而且更轻便,可以和carrywave连用进行上传,也有rails的一键安装程序,自己去github上面找。而ckeditor界面太复杂了,而且和rails连用时的那个github上的程序是用paperclip进行上传的,paperclip我居然没有成功使用起来,:-)

ckeditor https://github.com/galetahub/ckeditor 我觉得功能挺全,支持ajax上传图片等功能,支持中文,界面可以定制,和rails集成了,就用了一用。
按照github的文档安装,期间在执行rails generate ckeditor:install的时候报错:

gsub  public/javascripts/ckeditor/plugins/image/dialogs/image.js
fetching rails.js 
/home/zj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:678:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
from /home/zj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:678:in `block in connect'
from /home/zj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
from /home/zj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:89:in `timeout'
from /home/zj/.rvm/rubies/ruby-1.9.2-
...
from /home/zj/.rvm/gems/ruby-1.9.2-p290@rails3.1.0/gems/ckeditor-3.6.3/lib/generators/ckeditor/install_generator.rb:59:in `download_javascripts'
...
from script/rails:6:in `require'
from script/rails:6:in `<main>'
解决办法:修改install_generator.rb
在class InstallGenerator < Rails::Generators::Base这一行后面加:
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
就好了

我是按照
rails generate ckeditor:install这样安装的,会被装到/public/javascripts/ckeditor下。也可按照
rails generate ckeditor:install --path=public/assets这样的方法安装,因为这样会被装到/public/assets下,这个目录是rails assets pipline预编译的目标路径,也许更好吧。后来我把我安装文件拷贝到了/public/assets/javascripts/ckeditor下

后来报错
Sprockets::FileOutsidePaths in News#new

Showing /home/zj/cms/app/views/news/new.html.haml where line #2 raised:

/javascripts/ckeditor/ckeditor.js isn't in paths: /home/zj/cms/app/assets/images, /home/zj/cms/app/assets/javascripts, /home/zj/cms/app/assets/stylesheets, /home/zj/cms/vendor/assets/stylesheets, /home/zj/.rvm/gems/ruby-1.9.2-p290@rails3.1.0/gems/jquery-rails-1.0.16/vendor/assets/javascripts
Extracted source (around line #2):

%head
  = javascript_include_tag "/javascripts/ckeditor/ckeditor.js"
错就错在最前面如果加/,导致查找/app下的目录路径,去掉/则查找public/assets目录下,这才是正确的
http://127.0.0.1:3000/assets/javascripts/ckeditor/_samples/index.html是例子

后来改config.js里面的language为zh-cn,但无效,因为生成的js里面有language:en。所以我自己重新封装了一下,方法如下:
application_helper.rb
module ApplicationHelper
  def ckeditor_js(name)
    raw "<script type=\"text/javascript\">\n<!-- /<![CDATA[ -->\nif (CKEDITOR.instances['"+name+"']) {CKEDITOR.remove(CKEDITOR.instances['"+name+"']);}CKEDITOR.replace('"+name+"', { language: 'zh-cn' });\n<!-- /]]> -->\n</script>"
  end
end

_form.html.haml
=f.text_area :content
=ckeditor_js "news_content"