2007-02-05
FCKEditor与rails的集成
http://www.blogjava.net/rocky/archive/2006/11/04/rails-fckeditor-integration.html
1.下载fckeditor_plugin-0.3.2.zip,目前版本为0.3.2
2.解压到vendorplugins目录下,并且重新命名为fckeditor
3.到该应用程序根目录下,然后运行rake fckeditor:install,则执行自动安装
4.在自己的view层中添加
以及在你需要编辑的字段textarea替换为
第一个参数为你的domain对象,desc为你的编辑字段值,其他顾名思义
然后运行你的页面程序,发现simple upload有点bug,上传后javascript报错
5.追踪代码发现
vendorplugins ckeditorappcontrollers ckeditor_controller.rb下的
def upload
self.upload_file
end调用了upload_file方法
def upload_file
@new_file = params[:NewFile]
@url = upload_directory_path
begin
ftype = @new_file.content_type.strip
if ! MIME_TYPES.include?(ftype)
@errorNumber = 202
puts "#{ftype} is invalid MIME type"
raise "#{ftype} is invalid MIME type"
else
path = current_directory_path + "/" + @new_file.original_filename
File.open(path,"wb",0664) do |fp|
FileUtils.copy_stream(@new_file, fp)
end
@errorNumber = 0
end
rescue => e
@errorNumber = 110 if @errorNumber.nil?
end
# Fix provided by Nicola Piccinini -- http://superfluo.org
render :text => %Q''
#render :inline => 'page << "window.parent.frames['frmUpload'].OnUploadCompleted(#{@errorNumber}, '#{@new_file}');"', :type => :rjs
end中的
render :text => %Q''在浏览服务器时是正常的,但是在快速上传中不应该返回这个script语句
则修改upload方法
def upload
@new_file = params[:NewFile]
@url = upload_directory_path
begin
ftype = @new_file.content_type.strip
if ! MIME_TYPES.include?(ftype)
@errorNumber = 202
puts "#{ftype} is invalid MIME type"
raise "#{ftype} is invalid MIME type"
else
path = current_directory_path + "/" + @new_file.original_filename
File.open(path,"wb",0664) do |fp|
FileUtils.copy_stream(@new_file, fp)
end
@errorNumber = 0
end
rescue => e
@errorNumber = 110 if @errorNumber.nil?
end
# Fix provided by Nicola Piccinini -- http://superfluo.org
render :text => %Q''
end快速上传问题修复
6.发现文件夹里边如果上传图片过多不好备份,故采用/年/月方式保存
修改代码如下:
def upload
@new_file = params[:NewFile]
@url = upload_directory_path
begin
ftype = @new_file.content_type.strip
if ! MIME_TYPES.include?(ftype)
@errorNumber = 202
puts "#{ftype} is invalid MIME type"
raise "#{ftype} is invalid MIME type"
else
path = date_directory_path + "/" + @new_file.original_filename
File.open(path,"wb",0664) do |fp|
FileUtils.copy_stream(@new_file, fp)
end
@errorNumber = 0
end
rescue => e
@errorNumber = 110 if @errorNumber.nil?
end
# Fix provided by Nicola Piccinini -- http://superfluo.org
render :text => %Q''
end
private
def date_directory_path
base_dir = "#{UPLOADED_ROOT}/#{params[:Type]}/#{Time.now.year}/#{Time.now.month}"
#Dir.mkdir(base_dir,0775) unless File.exists?(base_dir)
FileUtils.mkdir_p base_dir
"#{base_dir}"
end
7.同理可以对其上传文件名称进行随机处理以防重名,就不多说了。
做此笔记,抛砖引玉。
发现rails的plugin机制挺不错的,比较灵活,不过网上介绍plugin的文章真的不是很多
1.下载fckeditor_plugin-0.3.2.zip,目前版本为0.3.2
2.解压到vendorplugins目录下,并且重新命名为fckeditor
3.到该应用程序根目录下,然后运行rake fckeditor:install,则执行自动安装
4.在自己的view层中添加
以及在你需要编辑的字段textarea替换为
第一个参数为你的domain对象,desc为你的编辑字段值,其他顾名思义
然后运行你的页面程序,发现simple upload有点bug,上传后javascript报错
5.追踪代码发现
vendorplugins ckeditorappcontrollers ckeditor_controller.rb下的
def upload
self.upload_file
end调用了upload_file方法
def upload_file
@new_file = params[:NewFile]
@url = upload_directory_path
begin
ftype = @new_file.content_type.strip
if ! MIME_TYPES.include?(ftype)
@errorNumber = 202
puts "#{ftype} is invalid MIME type"
raise "#{ftype} is invalid MIME type"
else
path = current_directory_path + "/" + @new_file.original_filename
File.open(path,"wb",0664) do |fp|
FileUtils.copy_stream(@new_file, fp)
end
@errorNumber = 0
end
rescue => e
@errorNumber = 110 if @errorNumber.nil?
end
# Fix provided by Nicola Piccinini -- http://superfluo.org
render :text => %Q''
#render :inline => 'page << "window.parent.frames['frmUpload'].OnUploadCompleted(#{@errorNumber}, '#{@new_file}');"', :type => :rjs
end中的
render :text => %Q''在浏览服务器时是正常的,但是在快速上传中不应该返回这个script语句
则修改upload方法
def upload
@new_file = params[:NewFile]
@url = upload_directory_path
begin
ftype = @new_file.content_type.strip
if ! MIME_TYPES.include?(ftype)
@errorNumber = 202
puts "#{ftype} is invalid MIME type"
raise "#{ftype} is invalid MIME type"
else
path = current_directory_path + "/" + @new_file.original_filename
File.open(path,"wb",0664) do |fp|
FileUtils.copy_stream(@new_file, fp)
end
@errorNumber = 0
end
rescue => e
@errorNumber = 110 if @errorNumber.nil?
end
# Fix provided by Nicola Piccinini -- http://superfluo.org
render :text => %Q''
end快速上传问题修复
6.发现文件夹里边如果上传图片过多不好备份,故采用/年/月方式保存
修改代码如下:
def upload
@new_file = params[:NewFile]
@url = upload_directory_path
begin
ftype = @new_file.content_type.strip
if ! MIME_TYPES.include?(ftype)
@errorNumber = 202
puts "#{ftype} is invalid MIME type"
raise "#{ftype} is invalid MIME type"
else
path = date_directory_path + "/" + @new_file.original_filename
File.open(path,"wb",0664) do |fp|
FileUtils.copy_stream(@new_file, fp)
end
@errorNumber = 0
end
rescue => e
@errorNumber = 110 if @errorNumber.nil?
end
# Fix provided by Nicola Piccinini -- http://superfluo.org
render :text => %Q''
end
private
def date_directory_path
base_dir = "#{UPLOADED_ROOT}/#{params[:Type]}/#{Time.now.year}/#{Time.now.month}"
#Dir.mkdir(base_dir,0775) unless File.exists?(base_dir)
FileUtils.mkdir_p base_dir
"#{base_dir}"
end
7.同理可以对其上传文件名称进行随机处理以防重名,就不多说了。
做此笔记,抛砖引玉。
发现rails的plugin机制挺不错的,比较灵活,不过网上介绍plugin的文章真的不是很多
- 10:28
- 浏览 (822)
- 评论 (0)
- 分类: Ruby On Rails
- 相关推荐
发表评论
- 浏览: 10645 次

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
整合File-Column和Rmagic ...
3.安装file-column到app的vendor目录里,直接copy过去就行 ...
-- by xieqibao -
Paginate a collection or ...
我以前有花點時間寫這個東西 Maybe helpful http://ligh ...
-- by thegiive -
Dave 喜欢 Rails 的十大 ...
哈哈,没有XML,这个对我来说也是一个很重要的好处。
-- by ouspec -
Paginate a collection or ...
def list_for_one_category @category = ...
-- by koska -
Paginate a collection or ...
如果能有一个完整的例子就好了
-- by wiwolf






评论排行榜