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.
#create.js.erb
$("#promo_types").append("<%= escape_javascript(render(:partial => "promotion_type"))%>");
it is throwing an error: 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
#index.erb
<div id="promo_types">
<%= render :partial => "promotion_type" %>
</div>
#_promotion_type
<% @promotion_types.each do |@promotion_type| %>
<table>
<tr>
<td width="200"><%=h @promotion_type.name %></td>
<td width="20"><a class="Edit<%=h @promotion_type.id %>" href="#"><img src="/images/pencil.png" alt="Edit" title="Edit" /></a></td>
<td width="20"><%= link_to(image_tag('/images/bin.png', :alt => 'Remove', :title => "Remove"), @promotion_type, :class => "deleteCategory") %></td>
</tr>
</table>
<div id="popupEdit<%=h @promotion_type.id %>" class="popupEdit">
<a class="popupClose<%=h @promotion_type.id %>" id="popupClose">x</a>
<%= render :file => 'promotion_types/edit' %></div>
<% end %>
It doesn't like that first line of code of the partial when I try to append the row using ajax.
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?
EDIT:
#full create.js.erb
$("#promo_types").append(<% escape_javascript(render(:partial => "promotion_type"))%>");
$("new_promotion_type")[0].reset();
$(".addtoggle01").toggle();
$(".addtoggle01").before('<div id="notice">Your promotion type has been successfully submitted.</div>');
It resets my form, hides the form, and displays the notice, but it isn't appending anything and not throwing any errors either.