Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails: error when using unobtrusive JavaScript to update partial
    primarykey
    data
    text
    <p>I am using Rails 3.2.13, and I'm trying to update a 'summary' partial after creating a 'child' item.</p> <p>I have a template and template tasks, and what I am trying to do is update the partial on the 'show' view, which is a summary that indicates how many tasks are allocated to the template. I am doing this in the <code>create.js.erb</code> of the template task.</p> <p>Here are the contents of <code>_template-summary.html.erb</code>:</p> <pre><code>&lt;div id="template-summary-details"&gt; &lt;table class="table table-striped"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;span class="fa fa-th-list"&gt;&lt;/span&gt; No. of tasks&lt;/td&gt; &lt;td&gt;&lt;%= @template.templatetasks.count %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span class="fa fa-clock-o"&gt;&lt;/span&gt; Total task days&lt;/td&gt; &lt;td&gt; &lt;%= @template.templatetasks.sum(:days) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span class="fa fa-check-square-o"&gt;&lt;/span&gt; No. of checklists&lt;/td&gt; &lt;td&gt; &lt;%= @template.templatetasks.count(:checklist_id) %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>And here are the contents of <code>create.js.erb</code>:</p> <pre><code>&lt;% @template = Template.where("id = ?", @templatetask.template_id?) %&gt; $("#template-summary-details").replaceWith("&lt;%= escape_javascript(render partial: "templates/template-summary", locals: {template: @template}) %&gt;"); &lt;% if @templatetask.parent_id? %&gt; $('#templatetasks'+&lt;%= @templatetask.parent_id %&gt;).prepend('&lt;%= j render(@templatetask) %&gt;'); &lt;% else %&gt; $('#templatetasks').prepend('&lt;%= j render(@templatetask) %&gt;'); &lt;% end %&gt; </code></pre> <p>The problem is that I am getting the following error: </p> <pre><code>undefined method `where' for ActionView::Template:Class </code></pre> <p>I have also tried using <code>find</code> but haven't gotten that to work either.</p> <p>How else would I pass the <code>@template</code> to the partial during the creation of a template task?</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.
    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