Skip to content

FCKEditor Plugin for Rails

Following on from my experiences with FCKEditor and Rails, I decided to wrap the whole thing up as a plugin. This can be downloaded here or installed using the plugin install command, see this post

It basically combines and extends the following pieces of work:

  1. Integrate FCKEditor with your Ruby on Rails application
    By Joshua M Charles
  2. Implementation details for FCKEditor integration with Ruby on Rails
  3. FCKEditor On Rails

The end result is the editor with a working resource manager and a set of helpers that allow use with both AJAX and basic HTML forms.

Install

  1. Download and extract the tar in your plugins directory
  2. Run ‘rake fckeditor:install’ from the root of your rails application
  3. Add <%= javascript_include_tag “fckeditor/fckeditor” %> to the layout / head of the page you wish to use the editor on.
  4. Use the editor as shown below

Using with AJAX

<%= form_remote_tag :url => { :action => 'view', :id => @comment },
                    :before => fckeditor_before_js('comment', 'comment') %>

    <div id="<%= fckeditor_div_id('comment', 'comment') %>">
        <%= fckeditor_textarea( "comment", "comment", :ajax => true ) %>
    </div>
<% end_form_tag %>

Using with HTML

<%= form_tag :action => 'new' %>

    <div id="<%= fckeditor_div_id('comment', 'comment') %>">
        <%= fckeditor_textarea( "comment", "comment" ) %>
    </div>
<% end_form_tag %>

40 Comments

  1. photusEnigma wrote:

    Nice! I was starting to look into creating something like this as I didn’t expect an integration like this to be available yet (I’m a big FCKeditor fan and have used it in PHP & .NET, but not in any Rails projects yet), and am thrilled to find out it’s already done and available for public use! Won’t be able to get to playing with it today, but can’t wait to see how it works in the project I’m currently working on!

    Monday, August 7, 2006 at 2:02 pm | Permalink
  2. Mizan wrote:

    Nice job… salute..

    Thanks
    Mizanur Rahman

    Monday, August 7, 2006 at 2:02 pm | Permalink
  3. Jerry wrote:

    When i run rake fckeditor:install
    It show:Don’t know how to build task ‘fckeditor:install’
    I don’t know why

    Monday, August 7, 2006 at 2:02 pm | Permalink
  4. Scott Rutherford wrote:

    Hi Jerry,

    You need to run the task from the root of your rails app, is that where you were?

    Cheers
    Scott.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  5. n wrote:

    hmm, everything works but the file browser:
    when i click on image and then on file browser, it opens a new window but i get an xml request error and it shows neither file nor does it let me upload file or create a folder;

    snooped around but can’t find anything. any ideas anyone?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  6. n wrote:

    ah i figured it out … just needed to tweak the settings file a bit;
    also there is a nice troubleshooting page here: http://wiki.fckeditor.net/Troubleshooting

    Monday, August 7, 2006 at 2:02 pm | Permalink
  7. Scott Rutherford wrote:

    @n great glad you got it working. thanks for the link. Scott.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  8. DAvid wrote:

    Hi, it works fine in IE , but ? I can’t get it to work in firefox… The text area doesn’t appear and I get this javascript error : "this.DOMDocument has no properties" … Any idea on how to resolve this issue?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  9. Scott Rutherford wrote:

    @David, I’m not sure why you are getting that. It works fine for me in Firefox. Email me with more details if you don’t make any progress.

    Cheers
    Scott.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  10. What would be the most elegant way of throwing a before_filter in front of the fckeditor controller? I REALLY don’t like the idea of leaving a controller with filesystem read/write privileges out in the open.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  11. Scott Rutherford wrote:

    Hi Dan, what is it you want to do with the before_filter?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  12. acw1668 wrote:

    Hi Scott,
    I have the same problem mentioned by David: the editing area is not shown in Firefox (both 1.5.0.x and 2.0), only the toolbars are shown. Error "this.DOMDocument has no properties" in fckeditorcode_gecko.js line 43 is shown in JavaScript Console. I’m using the lastest fckeditor-plugin version 0.4.0. Is the problem identified and solved?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  13. Scott Rutherford wrote:

    Hi acw1668, I had another person contact me about this too. I have yet to see the issue but I will have to try and reproduce it and come up with a solution. I develop using FF2 so I know it works for me in that. Could you email me a stripped down version of the app so I could have a look? (scott [AT] caronsoftware.com)

    Cheers
    Scott

    Monday, August 7, 2006 at 2:02 pm | Permalink
  14. Chris wrote:

    Hi Scott…I bit off more than I could chew. I am new to Ruby on Rails and have been building a very basic CMS for my pops as my first "learning" project.

    So I thought, wouldn’t it be nice if I integrated FCKeditor …and followed all of the steps above, and now when I go to the page I dropped the "Using with HTML" code from above I get the error:

    undefined method `fckeditor_div_id’

    The page URL is: http://www.ojealo.net/lapostita/subpage/rates.
    I plan to integrate it here eventually: http://www.ojealo.net/lapostita/admin (work in process)

    If you could give me some direction here I would really appreciate it.

    Thanks,
    Chris

    Monday, August 7, 2006 at 2:02 pm | Permalink
  15. James Penny wrote:

    In firefox, when calling the fckeditor_textarea try putting in a :height and :width

    After I put these values in the textarea box appeared

    Monday, August 7, 2006 at 2:02 pm | Permalink
  16. bq. Scott Rutherford Wed, 29 Nov 2006 11:43:35 GMT
    Hi Dan, what is it you want to do with the before_filter?

    Whoa. Sorry for the slow reply to your reply. . . Time slips away, doesn’t it.

    I simply want to authenticate/authorize users via methods I’ve already got in my ApplicationController. Wide open read/write privileges via the fckeditor controller are scary, and I want to lock that down.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  17. Scott Rutherford wrote:

    @Chris, you need to include this in your header:

    <%= javascript_include_tag :fckeditor %>

    @James, thanks for posting that up.

    @Dan, if you add a before_filter in application.rb as so:

    before_filter :require_login, :o nly => :command

    that should do it.

    Cheers
    Scott

    Monday, August 7, 2006 at 2:02 pm | Permalink
  18. Caspar wrote:

    I had the firefox issue aswell. I resolved it by specifying a toolbarset and width and height, width and height alone didn’t work for me.

    <%= fckeditor_textarea( :home_page_text, :text, :toolbarSet => ‘Simple’, :width => ’800′, :height => ’500′) %>

    Monday, August 7, 2006 at 2:02 pm | Permalink
  19. tony.chestnut@gmail.com wrote:

    I’m getting the XML request error: Internal Server Error (500) error and have no clue what could be causing it…railsfck.js was created with the necessary paths…the perms are correct for the uploaded folder….I looked at that page provided by an earlier comment…no help for rails apps….has anyone encountered this before…and how was it resolved?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  20. Kim wrote:

    How do I install this plugin – the download here link at the top of the page goes to an empty page.

    I am using radrails and FCKeditor is not on the list of plugins.

    Please help.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  21. Kim wrote:

    Sorry for the multiple posts before – I got it installed (but your link to rubyforg is broken)

    I have the FCKEditor_plugin files in my vendor/plugins folder.

    Now I cannot connect to my app – I get an Unable to connect Error – yes my server is started and the app works just find if I uninstall the plugin or move it to the vendor folder (have not even got to testing if the plugin works)

    Any suggestions?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  22. SpoBo wrote:

    hey, excellent plugin. It made my pain partially go away. But I have a small problem with AJAX. I have a form_remote with FCK in it. I have placed the before filter so it gets parsed. The values show up in my controller, but I actually update the page dynamically(inline in the controller, I tried an .rjs as well) in the action but after doing the before filter it refused to do this properly. It just outputted the JavaScript to my browser. Is there a way to get this back to normal?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  23. Mike Johnson wrote:

    Hey Scott, it appears your download link to RubyForge is broken. I went to the site and manually found this link (http://rubyforge.org/frs/download.php/15296/fckeditor_plugin-0.4.0.tgz)

    Monday, August 7, 2006 at 2:02 pm | Permalink
  24. Karel Minarik wrote:

    Hi Caspar, thanks for the tip, I was quite stuck in the "DOM element has no properties" in Firefox as well, and specifying the toolbar style has solved that issue.

    Karel

    Monday, August 7, 2006 at 2:02 pm | Permalink
  25. Shai Shefer wrote:

    Doesn’t work with Safari? (or is it just me?)

    Monday, August 7, 2006 at 2:02 pm | Permalink
  26. Nishant Sinha wrote:

    Hi, its very nice,but sometimes I want to disable it in my application.
    Before using this I use ‘:disabled=>true’ in my text area.

    I also try this in <%= fckeditor_textarea( "comment", "comment", :ajax => true, :disabled=>true) %> ,but it doesn’t work.

    So,please help me how to disable text area of FCK Editor.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  27. Kuy wrote:

    shai: FCKeditor itself doesn’t support Safari yet. More info here: http://www.fckeditor.net/safari

    Monday, August 7, 2006 at 2:02 pm | Permalink
  28. Reid wrote:

    Has anyone built a wiki or CMS in Ruby On Rails that uses this plugin?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  29. Nii Amon wrote:

    Hi all

    I just installed the plugin and I’m getting a rather strange error: can’t dup Symbol. This happens when i use the javascript_include_tag in the Readme that came with the plugin. Can anyone please give me an explanation as to why this is happening and maybe how to go about fixing it. Thanks alot.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  30. Routing problem with FckEditor in rails wrote:

    no route found to match "/javascript/editor/fckeditor.html" with {:method=>:get}

    when i try to used this solution it give me this error.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  31. Scott wrote:

    Hi, I haven’t seen that routing error. But I will have a look. Can you give me any more information?

    @Nii, sorry I didn’t answer been very busy. I suspect you have included some javascript twice (probably :defaults).

    Cheers
    Scott.

    Monday, August 7, 2006 at 2:02 pm | Permalink
  32. Peter wrote:

    Thank you!

    Monday, August 7, 2006 at 2:02 pm | Permalink
  33. kenrome@163.com wrote:

    When i run rake fckeditor:install It show:Don’t know how to build task ‘fckeditor:install’ I don’t know why

    please help me

    Monday, August 7, 2006 at 2:02 pm | Permalink
  34. Jean-Baptiste wrote:

    Thanks for this plugin ! It helps alot…
    But I’m having a little problem with uploads : I can create folders fine, but when I try uploading a file, any file, I’ll get a "Error on file upload. Error number: 403" popup…

    Any idea on what I’m doing wrong ?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  35. Jean-Baptiste wrote:

    Ok, I finally found out what wasn’t working. First, I was only trying with very small files. As soon as I began uploading bigger files, it worked. I discovered that with John Miller’s comment here : http://blog.caronsoftware.com/articles/2007/04/10/fckeditor-0-4-1-available. Small edit, and it now works nice !

    So, thanks for the plugin :)

    Monday, August 7, 2006 at 2:02 pm | Permalink
  36. renuka wrote:

    hi,
    i want to store images in uploads/users/user_id user_id is dynamic so can anyone say me how can i change path for that?
    please help me on this.
    give me reply as soon as possible

    thanks in advance

    Monday, August 7, 2006 at 2:02 pm | Permalink
  37. warren wrote:

    Any suggestions on how to get this to work in rails 2.0? Thanks,

    Monday, August 7, 2006 at 2:02 pm | Permalink
  38. Konstantin Tikhonov wrote:

    Hi, thanks for the plugin! I’m trying to write something like this:
    % fields_for "article[incuts][]", edit_incut do |form| -%>
    V<%= form.text_field :content, :size => 30 %>
    <% end -%>
    And I want to use fckeditor instead of text_field, but I can’t just write form.fckeditor_textarea :content. How can I use fckeditor plugin in complex forms like http://railscasts.com/episodes/73 ?

    Monday, August 7, 2006 at 2:02 pm | Permalink
  39. John wrote:

    I have recently upgraded an application to Rails 2.0.2. The fckeditor itself works, however the image file manager does not. It looks like the connector is not being found by the rails router. I get the following error message in the log:

    Processing ApplicationController#index (for 127.0.0.1 at 2008-05-06 13:56:48) [GET]
    Session ID: 80ebd6bcf483bad22183bb3b01a9bd10
    Parameters: {"CurrentFolder"=>"/", "Command"=>"GetFoldersAndFiles", "uuid"=>"1210096608457", "Type"=>"Image"}

    ActionController::RoutingError (No route matches "/fckeditor/command" with {:method=>:get}):

    Has anyone else seen this problem? Any hints about how to fix it, much appreciated in advance.

    – John

    Monday, August 7, 2006 at 2:02 pm | Permalink
  40. Scott wrote:

    Hi John, I copied this over to the most recent "post":http://blog.caronsoftware.com/2008/2/6/fckeditor-plugin-0-4-3-released. As that I hope is where most people land, although it may not be. I’ll have a look if I can replicate this.

    Scott

    Monday, August 7, 2006 at 2:02 pm | Permalink