Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:34:59+00:00 2026-05-25T12:34:59+00:00

I am using Rails 3.0.9 with the ckedit gem. I have the following code

  • 0

I am using Rails 3.0.9 with the ckedit gem.

I have the following code in a view.

<%= f.cktext_area :content, :toolbar => 'Reduced', :width => 550, :height => 300 %>

How can I style the resulting editor to set the background-color of the edit area to indicate that validation has failed? For <%=text_area I can set :class=>'error' but I can’t figure out the correct approach.

Many thanks for your help – I’ve searched everywhere for a decent answer this!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:35:00+00:00Added an answer on May 25, 2026 at 12:35 pm

    I haven’t worked with the ckedit gem (or Rails for that matter), but here are some config settings and methods you can try.


    You can assign the class (or ID) when you create the instance using a config setting:

    <%= f.cktext_area :content, :bodyClass => 'yourBodyClass', :bodyId => 'yourBodyId'>
    

    Here’s the api page:
    http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.bodyClass


    You can use the addCss method when you create the instance. This is an example that works when creating the editor instance with JavaScript.

    It’s possible to put this in your CKEditor config file which might be better in your case because you’re creating the CKEditor object using server side code. See below for further details.

    CKEDITOR.replace( 'content' );
    CKEDITOR.instances.content.addCss( 'body { background-color: red; }' );
    

    Here’s the API page:
    http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#addCss


    You may want to change the color based on circumstances. If so, you can put a JavaScript or Rails variable in place of the color to make it dynamic.

    var colorValue = '<%= colorVariable >';
    
    CKEDITOR.instances.content.addCss( 'body { background-color: '+colorValue+'; }' );
    CKEDITOR.instances.content.addCss( 'body { background-color: '<%= colorVariable >'; }' );
    

    Not sure about the Rails syntax, but you get the idea.


    Putting the “addCss” method in your CKEditor config file:
    You need to put it at the top of the file before “CKEDITOR.editorConfig” is called. It use’s the exact same syntax as above and can use a variable to set a dynamic color as described above.


    The “addCss” method has no effect if called after the editor instance is loaded.

    If your validation is being done with JavaScript and you need set the background color after everything has loaded (without reloading the page), you can try the following approach.

    You can insert the following code into the page that contains the editor instance. You would call “setIframeBackground()” when validation fails. If the color doesn’t change, you can hard code it and remove the parameter from the function.

    The code assumes that you used the “bodyId” config option described above to set the Id of the content area iframe body to “yourBodyId”.

    One caveat, I used jQuery to write this code.

    // Wait for the document ready event
    $(document).ready(function(){
    
      // Wait for the instanceReady event to fire for the "content" instance
      // The instance name is "content"
      CKEDITOR.instances.content.on( 'instanceReady',
        function( instanceReadyEventObj )
        {
          var currentEditorInstance = instanceReadyEventObj.editor;
          var iframeDoc=null;
    
          // Create the function
          function setIframeBackground( colorVariable )
          {
            // The CKEditor content iframe doesn't have a Name, Id or Class
            // So, we'll assign an ID to the iframe
            // it's inside a table data cell that does have an Id.
            // The Id of the data cell is "cke_contents_content"
            // Note that the instance name is the last part of the Id
            // I'll follow this convention and use an Id of "cke_contents_iframe_content"
    
            $("#cke_contents_content iframe").attr("id", "cke_contents_iframe_content");
    
            // Now use the iframe Id to get the iframe document object
            // We'll need this to set the context and access items inside the iframe
    
            $('#cke_iframe_content').each(
              function(){ iframeDoc=this.contentWindow.document;}
            );
    
            // Finally we can access the iframe body and set the background color.
            // The Id of the body is set to "yourBodyId".
            // We use the iframe document object (iframeDoc) to set the context.
            // We use the "colorVariable" variable assigned in the function call.
    
            $('#' + yourBodyId, iframeDoc).css("background-color", colorVariable);
          }
        }
      );
    });
    

    Be Well,
    Joe

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Note: Using Rails 3.1 and current delayed_job gem. I have a User model that
I am using Rails 3.1 . Here is the code I have which asks
Using Rails 3.0, I have a small bit of code that I seem to
Using Rails v2.1, lets say you have an action for a controller that is
I am using rails beta 3 and I have a erb page named index.html.erb
Using Rails 3.2 and ruby 1.9.3p0 I am trying out the gem delayed_job. I
Using Rails 3 active relation, I have a scope: scope :duplicate_contact, lambda {|contact| where(
Using Rails 3.0.7. I have a simple form which shows all records from one
i m using rails 2.3.3 and web browser Firefox i have added ajax and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.