Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your <code>_promotion_type</code> partial you are looping through <code>@promotion_types</code> and it sounds like this instance variable is not getting set in the <code>create</code> action.</p> <p>From the name, it sounds like that partial should only display one promotion type, not many. So move the loop outside of the partial. I recommend using the <code>:collection</code> and <code>:object</code> options to pass the model to the partial.</p> <pre><code># index.html.erb &lt;div id="promo_types"&gt; &lt;%= render :partial =&gt; "promotion_type", :collection =&gt; @promotion_types %&gt; &lt;/div&gt; # _promotion_type.html.erb &lt;table&gt; &lt;tr&gt; &lt;td width="200"&gt;&lt;%=h promotion_type.name %&gt;&lt;/td&gt; &lt;td width="20"&gt;&lt;a class="Edit&lt;%=h promotion_type.id %&gt;" href="#"&gt;&lt;img src="/images/pencil.png" alt="Edit" title="Edit" /&gt;&lt;/a&gt;&lt;/td&gt; &lt;td width="20"&gt;&lt;%= link_to(image_tag('/images/bin.png', :alt =&gt; 'Remove', :title =&gt; "Remove"), promotion_type, :class =&gt; "deleteCategory") %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div id="popupEdit&lt;%=h promotion_type.id %&gt;" class="popupEdit"&gt; &lt;a class="popupClose&lt;%=h promotion_type.id %&gt;" id="popupClose"&gt;x&lt;/a&gt; &lt;%= render :file =&gt; 'promotion_types/edit' %&gt;&lt;/div&gt; # create.js.erb $("#promo_types").append("&lt;%= escape_javascript(render(:partial =&gt; "promotion_type", :object =&gt; @promotion_type))%&gt;"); </code></pre> <p>As for your second question, yes. You can assign a specific ID to each record and replace that using the <code>.html</code> method.</p> <pre><code># update.js.erb $("#promo_type_&lt;%= @promotion_type.id %&gt;").html("&lt;%= escape_javascript(render(:partial =&gt; "promotion_type", :object =&gt; @promotion_type))%&gt;"); </code></pre>
 

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