我正在使用Rails 3.2.13,並且在創建'child'項目後嘗試更新'summary'部分。Ruby on Rails:使用不顯眼的JavaScript更新部分時出錯
我有一個模板和模板任務,我試圖做的是更新'顯示'視圖,這是一個摘要,指示有多少任務分配給模板的部分。我正在模板任務的create.js.erb
中執行此操作。
這裏是_template-summary.html.erb
內容:
<div id="template-summary-details">
<table class="table table-striped">
<tbody>
<tr>
<td><span class="fa fa-th-list"></span> No. of tasks</td>
<td><%= @template.templatetasks.count %></td>
</tr>
<tr>
<td><span class="fa fa-clock-o"></span> Total task days</td>
<td>
<%= @template.templatetasks.sum(:days) %>
</td>
</tr>
<tr>
<td><span class="fa fa-check-square-o"></span> No. of checklists</td>
<td>
<%= @template.templatetasks.count(:checklist_id) %>
</td>
</tr>
</tbody>
</table>
</div>
這裏是create.js.erb
內容:
<% @template = Template.where("id = ?", @templatetask.template_id?) %>
$("#template-summary-details").replaceWith("<%= escape_javascript(render partial: "templates/template-summary", locals: {template: @template}) %>");
<% if @templatetask.parent_id? %>
$('#templatetasks'+<%= @templatetask.parent_id %>).prepend('<%= j render(@templatetask) %>');
<% else %>
$('#templatetasks').prepend('<%= j render(@templatetask) %>');
<% end %>
的問題是,我收到以下錯誤:
undefined method `where' for ActionView::Template:Class
我也嘗試過使用find
但是避風港也沒有得到那個工作。
如何在創建模板任務期間將@template
傳遞給partial?
謝謝你的迴應..設法讓它工作;) –