fckeditor on rails with 2.2

fckeditor http://rubyforge.org/frs/?group_id=2038&release_id=23116 最新版本 0.5.1

复制到plugins下面 执行 rake fckeditor:install

执行成功后重启web server



<%= javascript_include_tag :fckeditor %>


出现 undefined method `relative_url_root ' for ActionController::CgiRequest

 

是因为rails2.2已经没有 relative_url_root 这个方法了

 

所以要改2个地方

 

app/controllers/fckeditor_controller.rb

 

找到
uploaded = request.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}"

改成

uploaded =
ActionController::Base.relative_url_root.to_s+"#{UPLOADED}/#{params[:Type]}"

 

找到

js_path = "#{request.relative_url_root}/javascripts"

改成

js_path = "#{ActionController::Base.relative_url_root}/javascripts"

 

重启web server

ok

 

上传图片

出现js错误

 

app/controllers/fckeditor_controller.rb

upload_file方法最后返回JS改成

 

render :text => %Q'<script>window.parent.OnUploadCompleted(#{@errorNumber},\"#{UPLOADED}/#{params[:Type]}/#{Time.now.year}/#{Time.now.month}/#{@new_file.original_filename}\",\"#{@new_file.original_filename}\",\"\");</script>'

 

修改上传文件夹

 def date_directory_path
    base_dir = "#{UPLOADED_ROOT}/#{params[:Type]}/#{Time.now.year}/#{Time.now.month}"
    FileUtils.mkdir_p base_dir
    "#{base_dir}"
  end

你可能感兴趣的:(JavaScript,Web,fckeditor,Rails)