Kindeditor for Rails3, including image and file upload using carrierwave.
Add this to your Gemfile
gem "carrierwave" gem "rails_kindeditor"
Run “bundle” command.
bundle
Run install generator:
rails generate rails_kindeditor:install
That’s all! By default, rails_kindeditor do not save upload file information into database.
Basically include <%= include_kindeditor_if_needed %> under the <head> element of your in your layout file:
<%= include_kindeditor_if_needed %>
In your controller, use include_kindeditor method to load kindeditor:
include_kindeditor or include_kindeditor :only => [:new, :edit]
Assign your textarea with id in your form:
:id => "kindeditor_id"
That’s all.
When you run “rails generate rails_kindeditor:install”, installer will copy uploader files in you app/uploaders folder. Just modify “BASE_DIR” or “store_dir” in asset_uploader.rb.
rails_kindeditor can save upload file information into database.
Just run migration generate, there are two ORM options for you: 1.active_record 2.mongoid, default is active_record.
rails generate rails_kindeditor:migration or rails generate rails_kindeditor:migration -o mongoid
The generator will copy model and migration to your application. When you are done, remember run rake db:migrate:
rake db:migrate
That’s all.
You can load kindeditor javascript only in some action if you needed:
include_kindeditor :only => [:new, :edit] include_kindeditor :except => [:index, :show, :destroy, :create]
You can config kindeditor by kindeditor-init.js file, please read Kindeditor’s documents:
public/kindeditor/kindeditor-init.js [Rails3.1] public/javascripts/kindeditor/kindeditor-init.js [Rails3.0.x]
MIT License. Copyright 2011
可供Rails3使用的gem, 包括了图片和附件上传功能,文件按照类型、日期进行存储。上传采用了Carrierwave。
将下面代码加入Gemfile:
gem "carrierwave" gem "rails_kindeditor"
运行“bundle”命令:
bundle
安装Kindeditor,运行下面的代码:
rails generate rails_kindeditor:install
完毕!默认情况下,rails_kindeditor在上传文件时不会把文件信息记录入数据库。
在你的layout文件中的<head></head>内包含下面代码:
<%= include_kindeditor_if_needed %>
在你需要使用的controller里面,包含下面代码来控制加载javascript:
include_kindeditor 或者 include_kindeditor :only => [:new, :edit]
把需要转换的textarea赋予下列id值:
:id => "kindeditor_id"
完毕!
当你运行“rails generate rails_kindeditor:install”的时候,安装器会将uploader拷贝到app/uploaders文件夹。 在asset_uploader.rb文件中修改“BASE_DIR”或者“store_dir”即可(可参考Carrierwave)。
rails_kindeditor 可以将上传文件信息记录入数据库,以便扩展应用.
运行下面的代码,有两项选项:1.active_record 2.mongoid,默认是active_record。
rails generate rails_kindeditor:migration or rails generate rails_kindeditor:migration -o mongoid
运行下面的代码:
rake db:migrate
完毕!
你可以有选择性地加载kindeditor的javascript:
include_kindeditor :only => [:new, :edit] include_kindeditor :except => [:index, :show, :destroy, :create]
你可以通过修改kindeditor-init.js来配置kindeditor,详细配置方法可以阅读Kindeditor的文档:
public/kindeditor/kindeditor-init.js [Rails3.1] public/javascripts/kindeditor/kindeditor-init.js [Rails3.0.x]在本人博客中有写过rails 3 assets 文件下有三个文件的文章,在这里 rails3.1在app下有assets文件放有所有的js、css等。把public文件下的kindeditor文件夹剪切到assets/javascripts目录下,在layout文件中无须添加