Note that there are some explanatory texts on larger screens.

plurals
  1. PORails3 ujs javascript/html is displayed not executed
    text
    copied!<p>I am trying to write rails3/ujs with a fairly simple app. </p> <p>What I want is the javascript to be executed. What I get is the js or html code being executed on the new action, but displayed on the page on the edit action. </p> <p>An edit is triggered by</p> <pre><code>&lt;%= link_to image_tag("tx.png"), edit_publication_path(p,:format=&gt;:js), :remote=&gt;true -%&gt; </code></pre> <p>which becomes</p> <pre><code>&lt;a data-remote="true" href="/publications/154/edit.js"&gt;...&lt;/a&gt; </code></pre> <p>A new is triggered by</p> <pre><code>&lt;%= form_tag new_publication_path, :remote=&gt;true, :method=&gt;:get, :class=&gt;:Button do %&gt; &lt;%= submit_tag "Add New Publication" %&gt; &lt;%= select "publication", :type, %w(Journal Report Technical Conference Keynote Chapter Book), {:include_blank =&gt; false},:class=&gt;'dropdown' %&gt; &lt;% end %&gt; </code></pre> <p>which becomes </p> <pre><code>&lt;form method="get" data-remote="true" action="/publications/new" accept-charset="UTF-8" &gt; &lt;input type="submit" value="Add New Publication" name="commit"&gt; &lt;select name="publication[type]" id="publication_type"&gt; &lt;option value="Journal"&gt;Journal&lt;/option&gt;...&lt;option value="Book"&gt;Book&lt;/option&gt; &lt;/select&gt; &lt;/form&gt; </code></pre> <p>The controller handles both new and edit actions together thus:</p> <pre><code>def edit get_all_tags @object = params[:id].blank?? params[:publication][:type].constantize.new() : Publication.find(params[:id]) respond_to do |format| format.js # edit.js.erb end end </code></pre> <p>If I trigger the 'new' action then the javascript is executed and the view shows up with empty fields, ready to be filled.<br> If I trigger the 'edit' action the javascript and html are displayed on the screen.</p> <p>The js in question (edit.js.erb):</p> <pre><code>$("div#editDialog").dialog('open'). html('&lt;%= render(:layout=&gt;"layouts/edit.html",:template=&gt;"shared/edit.html")%&gt;'); </code></pre> <p>which displays as</p> <p><code>$("div#editDialog").dialog('open').html('&lt;div class="content edit_page ui-widget"&gt;&lt;form accept-charset="UTF-8" ... etc</code></p> <p>I can also escape_javascript the render statement which then displays</p> <p><code>$("div#editDialog").dialog('open').html('&lt;div class=\"content edit_page ui-widget\"&gt;\n...etc</code></p> <p>so is still not executing the javascript. Comparing the logs for the two actions shows all the same views being rendered.</p> <p>What have I missed here? (I was hoping that by writing it all out the solution would pop out for me, but it hasn't so far.)</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