rails3.2 下 ckeditor 的配置

升级到ruby1.9.3-p429 +rails3.2.13 ,发现原来的 ckeditor 的方式用不了了,Google 到解决方案
打开Gemfile,加入
gem ‘ckeditor’, ‘3.7.3’
如果要上传文件要安装 paperclip
gem ‘paperclip’, ‘~> 3.0’
然后用 bundle install 安装所需的gem
接下来是配置ORM和路由等
执行
rails generate ckeditor:install –orm=active_record –backend=paperclip
在config/applicaiton.rb中加入
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
在config/routes.rb中加入
mount Ckeditor::Engine => ‘/ckeditor’
上面这句也可能已经添加好了,如果没有,就自行添加即可。
在config/environments/production.rb中加入
config.assets.precompile += [‘ckeditor/*’]
然后执行
rake assets:precompile
查看public/assets/ckeditor目录是否存在,里面是否生成css文件和js文件。
在app/views/layouts/application.html.erb 引入helper javascript tag
<%= javascript_include_tag “ckeditor/ckeditor” %>
view页面中加入
<div class=”field”>
<%= cktext_area :post ,:content, :toolbar => ‘Full’, :width => 800, :height => 400 %>
</div>
存入 post#content 的是带有HTML标签的字符串,显示在页面上要用raw 禁止转义
<%= raw @post.content %>
 
源博客 http://virusswb.blog.51cto.com/115214/1048421
在1.9.3-p429 + rails3.2.13 下实测可用

reeoo.com - web design inspiration

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注