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







April 4th, 2009 at 12:18 pm
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’ veIt is still there…
April 21st, 2009 at 4:30 am
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
April 22nd, 2009 at 3:10 am
Thank you very much… it solves my problem.
July 8th, 2009 at 6:23 pm
Now getting:
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.
December 29th, 2009 at 3:42 pm
Very nice blog, your article is interesting, i have bookmarked it for future referrence
March 13th, 2010 at 12:15 pm
Hello There,
It’s really very simple & quick solution. Thank you very much…..
March 25th, 2010 at 7:18 am
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.