【发布时间】:2014-01-02 20:10:15
【问题描述】:
我使用的是 Rails 3.2.13,我正在尝试在创建“子”项目后更新“摘要”部分。
我有一个模板和模板任务,我想做的是更新“显示”视图上的部分内容,这是一个摘要,指示分配给模板的任务数量。我在模板任务的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 传递给部分?
【问题讨论】:
标签: javascript ruby-on-rails ruby-on-rails-3 unobtrusive-javascript