Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating html element by partial called from javascript file
    primarykey
    data
    text
    <p>I have a container <code>td</code> element that I populate successfuly with other elements using an HTML partial, it's done when the page loads.</p> <p>The partial runs over a <em>task</em> object that it gets as a param and desides which elements to add.</p> <p>After a specific action is done the <em>task</em> object is updated and I want to update the container by running the partial again.</p> <p>I'm calling this partial from my <code>create.js.haml</code> with the updated <em>task</em>, the partial runs and builds the correct updated HTML (I can see it in the Firebug response).</p> <p>But the actual page <strong>doesn't</strong> update. What am I missing here?</p> <p>Here are my files:</p> <p><code>html.haml</code> that holds the container <code>td</code>:</p> <pre><code>%td#task-categories{ :class =&gt; "#{dom_id(task)}_categories"} = render 'task_categories_mini_bar', :task =&gt; task </code></pre> <p>The partial <code>html.haml</code>:</p> <pre><code>- _MAX_DISPLAYED_CAT = 3 - cat_index = 0 - task.categories.each do |category| - if (cat_index == _MAX_DISPLAYED_CAT) %td{:style =&gt; "padding-left:1px; padding-right:5px"} ... - break - cat_index += 1 %td{ :class =&gt; "task-category-color_#{dom_id(category)}", :style =&gt; "width:60px; background:#{category.color}; border:solid 1pt lightblue; border-radius:3pt; text-align:center; "} = truncate(category.name, :length =&gt; 10) </code></pre> <p>Combined together they build this HTML:</p> <pre><code>&lt;td id="task-categories" class="task_3_categories"&gt; &lt;/td&gt; &lt;td class="task-category-color_category_1" style="width:60px; background:#b8d7ff; border:solid 1pt lightblue; border-radius:3pt; text-align:center; "&gt; cat1 &lt;/td&gt; &lt;td class="task-category-color_category_2" style="width:60px; background:#ff8fcb; border:solid 1pt lightblue; border-radius:3pt; text-align:center; "&gt; cat2 &lt;/td&gt; </code></pre> <p>There's another problem here - the two added category tds are added below the first container td. How can I add them to it and not after it?</p> <p>Now here is the <code>create.js.haml</code> that calls the partial again:</p> <pre><code>$('td.#{dom_id(@task)}_categories').html(#{escape_javascript(render(:partial =&gt; 'tasks/task_categories_mini_bar', :locals =&gt; {:task =&gt; @task}))}) </code></pre> <p>Again the response HTML does displays a new HTML but the page doesn't update.</p> <p>I'm using rails 3.0.10 Thanks allot, Eyal.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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