Note that there are some explanatory texts on larger screens.

plurals
  1. PORails, jQuery, Ajax create and update.js.erb
    primarykey
    data
    text
    <p>Alright. I am working with RoR and jQuery and I have already got my update and create links working and functioning with their .js.erb files. The problem arises when in create with this line of code.</p> <pre><code>#create.js.erb $("#promo_types").append("&lt;%= escape_javascript(render(:partial =&gt; "promotion_type"))%&gt;"); </code></pre> <p>it is throwing an error: <em>You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each</em></p> <pre><code>#index.erb &lt;div id="promo_types"&gt; &lt;%= render :partial =&gt; "promotion_type" %&gt; &lt;/div&gt; #_promotion_type &lt;% @promotion_types.each do |@promotion_type| %&gt; &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; &lt;% end %&gt; </code></pre> <p>It doesn't like that first line of code of the partial when I try to append the row using ajax.</p> <p>My only other question is concerning my update.js.erb. I works fine. If i click edit and update it updates the changes, but I don't see them till I refresh the page. I don't want to .append the partial because the would add the edit to the bottom of the list. Do I use a .html to refresh my partial thru AJAX?</p> <p>EDIT:</p> <pre><code>#full create.js.erb $("#promo_types").append(&lt;% escape_javascript(render(:partial =&gt; "promotion_type"))%&gt;"); $("new_promotion_type")[0].reset(); $(".addtoggle01").toggle(); $(".addtoggle01").before('&lt;div id="notice"&gt;Your promotion type has been successfully submitted.&lt;/div&gt;'); </code></pre> <p>It resets my form, hides the form, and displays the notice, but it isn't appending anything and not throwing any errors either.</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