RSS feed

Nutsmuggling

Patches for the easy-fckeditor rails plugin

A couple of days ago I discovered the wonderful easy-fckeditor Rails plugin. It’s a fork of the main fckeditor plugin, integrating the EasyUpload plugin. With this marvellous piece of software you can integrate a visual text editor in no time; what is more, file attachments are included out of the box, with no need to implement your own server-side upload actions.

The plugin is fantastic, but there was a small glitch with Rails 2.2, which forbade to upload files. Files upload is an ajaxed action, so you won’t see any error, unless you use firebug, which revealed this problem:

undefined method 'relative_url_root'

After some googling I found this patch which anyway is for the fckeditor plugin. So I tweaked it a bit and here’s the working patch for easy-fckeditor:

app/controllers/fckeditor_controller.rb

198
uploaded = request.relative_url_root.to_s + "#{UPLOAD_FOLDER}/#{params[:Type]}"

becomes:

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

lib/fckeditor.rb

38
js_path = "#{controller.relative_url_root}/javascripts"

becomes:

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

There was another small glitch, due to the interaction with safe_erb.
safe_erb is a super useful plugin which raises an error whenever unsanitized output is printed. This way you never risk forgetting to sanitize your stuff. The problem here is that html text is necessarily not sanitized, otherwise all the html tags would be lost. The trick here is to tell ruby that he can trust those strings. It’s not the most secure solution, but I guess it’s better to have everything but the html text sanitized than nothing…

libfckeditor.rb

15
value = value.nil? ? "" : value

becomes:

15
value = value.nil? ? "" : value.untaint()

I sent this patches to Gaston Ramos, the plugin maintainer, but you can follow my code if you stumble into this issues before the patches integration.

Davide

Share and Enjoy:
  • Digg
  • del.icio.us
  • Google
  • Technorati
  • StumbleUpon
  • Furl
  • Reddit

8 responses to “Patches for the easy-fckeditor rails plugin”

  1. Meneer R says:

    It doesn’t work with rails 2.2

    NoMethodError (undefined method relative_url_root' for #<ActionController::Request:0xb5a20bc4>): vendor/plugins/easy-fckeditor/app/controllers/fckeditor_controller.rb:198:inuploaddirectorypath’ ve

    It is still there… :-(

  2. Fernando says:

    Hi, I’m using rails 2.1.1 and already made the changes you suggest and I’m still getting that error. Any idea?

    urlroot = ActionController::Base.relativeurlroot.tos jspath = #{ActionController::Base.relativeurl_root}/javascripts”

    Thanks

  3. Juan Carlos says:

    Thank you very much… it solves my problem.

  4. Pi says:

    Now getting:

    $ruby script/plugin install git://github.com/gramos/easy-fckeditor.git
    /Library/Ruby/Site/1.8/rubygems/customrequire.rb:36:in gem_original_require': no such file to load -- active_support/core_ext/kernel (LoadError)
            from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:inrequire'
            from /Users/amalc/devel/srctop/srcruby/fe3/vendor/rails/railties/lib/commands/plugin.rb:109:in use_svn?'
            from /Users/amalc/devel/srctop/src_ruby/fe3/vendor/rails/railties/lib/commands/plugin.rb:126:inbestinstallmethod'
            from /Users/amalc/devel/srctop/srcruby/fe3/vendor/rails/railties/lib/commands/plugin.rb:788:in determine_install_method'
            from /Users/amalc/devel/srctop/src_ruby/fe3/vendor/rails/railties/lib/commands/plugin.rb:808:inparse!'
            from /Users/amalc/devel/srctop/srcruby/fe3/vendor/rails/railties/lib/commands/plugin.rb:518:in parse!'
            from /Users/amalc/devel/srctop/src_ruby/fe3/vendor/rails/railties/lib/commands/plugin.rb:534:inparse!'
            from /Users/amalc/devel/srctop/srcruby/fe3/vendor/rails/railties/lib/commands/plugin.rb:968
            from /Library/Ruby/Site/1.8/rubygems/customrequire.rb:31:in gem_original_require'
            from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire'
            from script/plugin:3
    

    Found a reference to this in rail.lighthouse.com as well as a bug but it is marked resolved.

    Running ruby 1.8.6, Rails 2.3.2 on MacOS 1.5.7 (9J61)

    Anybody else seen this?

    Thanks, Pi.

  5. teleskopy astronomiczne says:

    Very nice blog, your article is interesting, i have bookmarked it for future referrence

  6. Pradeep says:

    Hello There,

    It’s really very simple & quick solution. Thank you very much…..

  7. kiran says:

    hi, I m not able to upload my image through fckeditor

    its giving error as Unknown error creating folders, can anybody help me , i need it urgently.

  8. Very Short Curly Haircuts For Women says:

    Fantastic goods from you, man. I’ve bear in mind your stuff previous to and you are simply extremely great. I actually like what you have received right here, really like what you are stating and the way by which you say it. You’re making it enjoyable and you still care for to stay it sensible. I cant wait to learn far more from you. This is actually a great website.

Leave a Reply