I have a container td element that I populate successfuly with other elements using an HTML partial, it’s done when the page loads.
The partial runs over a task object that it gets as a param and desides which elements to add.
After a specific action is done the task object is updated and I want to update the container by running the partial again.
I’m calling this partial from my create.js.haml with the updated task, the partial runs and builds the correct updated HTML (I can see it in the Firebug response).
But the actual page doesn’t update. What am I missing here?
Here are my files:
html.haml that holds the container td:
%td#task-categories{ :class => "#{dom_id(task)}_categories"}
= render 'task_categories_mini_bar', :task => task
The partial html.haml:
- _MAX_DISPLAYED_CAT = 3
- cat_index = 0
- task.categories.each do |category|
- if (cat_index == _MAX_DISPLAYED_CAT)
%td{:style => "padding-left:1px; padding-right:5px"} ...
- break
- cat_index += 1
%td{ :class => "task-category-color_#{dom_id(category)}",
:style => "width:60px; background:#{category.color}; border:solid 1pt lightblue; border-radius:3pt; text-align:center; "}
= truncate(category.name, :length => 10)
Combined together they build this HTML:
<td id="task-categories" class="task_3_categories"> </td>
<td class="task-category-color_category_1" style="width:60px; background:#b8d7ff; border:solid 1pt lightblue; border-radius:3pt; text-align:center; "> cat1 </td>
<td class="task-category-color_category_2" style="width:60px; background:#ff8fcb; border:solid 1pt lightblue; border-radius:3pt; text-align:center; "> cat2 </td>
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?
Now here is the create.js.haml that calls the partial again:
$('td.#{dom_id(@task)}_categories').html(#{escape_javascript(render(:partial => 'tasks/task_categories_mini_bar', :locals => {:task => @task}))})
Again the response HTML does displays a new HTML but the page doesn’t update.
I’m using rails 3.0.10 Thanks allot, Eyal.
OK then, what I was missing was ” ” around the call for the partial in my ajax create.js.haml
Thats all.