找到的tiny_mce都是在rails2中的,唯一一个可以在rails3中简单使用的又不带上传功能,所以我在原来的rails2基础上修改了下,现在可以在rails3中工作了,不过本人所学有限,难免有bug,请见谅!
这个tiny_mce使用了jquery和will_pagnate,papaerclip,请先安装rails3版本
1,安装rails_tiny_mce plugin
rails plugin install git://github.com/doabit/rails-tiny-mce.git
rails g rails_tiny_mce_migration
rake db:migrate
2,更换rails的js库为jquery
http://github.com/rails/jquery-ujs/blob/master/src/rails.js download jqeuery.js
,
3.安装依赖的plugins
rake rails_tiny_mce:plugins
如果你已经存在responds_to_parent刚跳过
4.在application.html.erb中加入
<%= javascript_include_tag "jquery","rails"%>
<%= javascript_include_tiny_mce_if_used %>
<%= tiny_mce if using_tiny_mce? %>
5.在要使用的controller 上面加入
uses_tiny_mce(:options => AppConfig.default_mce_options, :only => [:new, :edit])
默认配置在config/initializers/tiny_mce_plus_config.rb中,可自行修改
6.给要使用编辑器的多行文本加上
:class => "mceEditor"
7.安装tiny_mac文件
rake rails_tiny_mce:install
8.修改routes.rb加入
match "attachments/manage(.:format)" => "attachments#manage"
match "/attachments/create(.:format)" => "/attachments#create"
下面是个简单的例子
Create CRUD for post
rails generate scaffold post title:string description:text
rake db:migrate
添加下面一行 posts_controller.rb
uses_tiny_mce(:options => AppConfig.default_mce_options, :only => [:new, :edit])
打开 /views/posts/new.html.erb 和 /views/posts/edit.html.erb
修改如下
<%= f.text_area :description %> to <%= f.text_area :description, :class => "mceEditor" %>