Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to replace the div in Rails 3 using AJAX?
    text
    copied!<p>I was trying to replace my div in DOM using RJS. Here is the code i tried, The controller has this method:</p> <pre class="lang-rb prettyprint-override"><code>def change render :update do |page| page.replace(:test_id, :partial =&gt; "input",:locals =&gt;{ :type =&gt; 'text', :name =&gt; 'user[user][contactinfo][city]', :val =&gt; "", :size =&gt; '244', :placeholder_text =&gt; 'Yes it is working...'}) end end </code></pre> <p>The view contains:</p> <pre><code>&lt;div id = "test_id"&gt;&lt;/div&gt; &lt;%= link_to "AJAX", "/poc/change", :remote =&gt; true %&gt; </code></pre> <p>Now I want to replace the <code>div id="test_id"</code> with the partial mentioned.</p> <p>The output i get is:</p> <pre><code>try { Element.replace("test_id", "&lt;input type=\"text\" id=\"user[user][contactinfo][city]\" name=\"user[user][contactinfo][city]\" value=\"\" placeholder=\"Yes it is working...\" style=\"width:244px; height:33px; border:0; color:#646464; background:url(/images/form_textfield_244.png) 0 5px no-repeat; padding:12px 5px 0 5px; margin:0 0 10px 0;\" /&gt;\n"); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.replace(\"test_id\", \"&lt;input type=\\\"text\\\" id=\\\"user[user][contactinfo][city]\\\" name=\\\"user[user][contactinfo][city]\\\" value=\\\"\\\" placeholder=\\\"Yes it is working...\\\" style=\\\"width:244px; height:33px; border:0; color:#646464; background:url(/images/form_textfield_244.png) 0 5px no-repeat; padding:12px 5px 0 5px; margin:0 0 10px 0;\\\" /&gt;\\n\");'); throw e } </code></pre> <p>This is seen in browser. Can anybody explain where I am going wrong? The expected output is the div should get replaced with whatever given for replacement.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload