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 1046265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:07:11+00:00 2026-05-16T16:07:11+00:00

In a Rails app, I am loading a partial via an ajax call. (still

  • 0

In a Rails app, I am loading a partial via an ajax call. (still using prototype)

The partial is a form that contains a textarea enriched with the yahoo yui_editor (similar to tinyMCE or FCKEditor)

<%= f.text_area :body, :class => 'rich_text_editor',  :rows => "15", :style => "width : 90%;"  %>

The yui_editor is not loaded and the textarea content is displayed as simple text when the form is loaded via an ajax call.

I tested that the yui_editor is active when the same partial is loaded directly without any ajax calls.

I know this has to do with the fact that the yui_editor javascript is not loaded but I have no idea how to solve this issue

Your help will be very much appreciated

Thanks

  • 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-16T16:07:11+00:00Added an answer on May 16, 2026 at 4:07 pm

    You need to start the YUI editor. Since the editor needs the id of the element, you need to specify a unique id in your partial.

    See the YUI doc for more on the editor’s parameters

    Added

    Are you adding the div via Ajax? In that case, you need to make the call to the YUI editor library after the div is added. Two ways to do that:

    1) Your code which does the insert into the dom (with the results of the Ajax call) needs to explicitly call the YUI editor. Eg your Ajax results could include the element id of the text area, you could already know it in advance, etc.

    2) You could include the script for calling the YUI editor in your Ajax results. But then you’ll need to run the script(s) in the html after you’ve added them to the dom.

    Setting innerHTML property of an element does NOT run any scripts in the html. But I have a script which does, see below.

    The script is based on this SO Question

    ... do ajax call and get results in <body>
    foo_el.innerHTML = body; // add results to the dom
    
    exec_body_scripts(foo_el); // run any scripts in foo_el
    
    //////////////////////////////////
    
    function exec_body_scripts(body_el) {
      // Finds and executes scripts in the dialog's body.
      // Needed since innerHTML does not run scripts.
      // NB: Only looks for scripts that are children or grandchildren of body_el.
      // Doesn't look deeper.  
    
      function evalScript(elem) {
        var data = (elem.text || elem.textContent || elem.innerHTML || "" ),
            head = document.getElementsByTagName("head")[0] ||
                   document.documentElement,
            script = document.createElement("script");
    
        script.type = "text/javascript";
        try {
          script.appendChild(document.createTextNode(data)); // doesn't work on ie
        } catch(e) {
          // IE has funky script nodes
          script.text = data;
        }
    
        head.insertBefore(script, head.firstChild);
        head.removeChild(script);
      };
    
      // main section of function
      var scripts = body_el.getElementsByTagName('SCRIPT'), i;
    
      for (i = 0; scripts[i]; i++) {
        evalScript(scripts[i]);
      }
    };    
    

    Partial example:

    <% el_id = "rte_#{foo.id}"
    # foo is the name of an object used by the partial. Using its id
    # to ensure a unique id for the element on the page.
    # Or use a simple counter "i". But in any case, the el_id must be unique
    %>
    <%= f.text_area :body, :class => 'rich_text_editor',  :rows => "15", 
        :style => "width : 90%;", :id => el_id  %>
    
    <script>
      (function() {
        var myEditor = new YAHOO.widget.Editor('<%= el_id %>', {
          height: '300px',
          width: '522px',
          dompath: true, //Turns on the bar at the bottom
          animate: true //Animates the opening, closing and moving of Editor windows
          });
        myEditor.render();
      })();    
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Using Rails 3.1.3) I have an app that manages products. I import the products
I have a rails app that I have serving up XML on an infrequent
I have a Rails app that I have successfully tested with Mongrel and Webkit.
I have a Rails app that I need to deploy. Here are the facts:
I have a rails app that has picked up a bit of traction, but
Rails does model loading on demand. For a rake task that I'm writing, I
I have three links in my Rails 3 app that load information in the
I have a Rails app that uses STI to handle different types of Users,
I've got a Rails app that has stopped caching somewhere along the way, and
I'm about to start rewriting bits and pieces of our Rails app that do

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.