Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2012 10:09
Show Gist options
  • Save anonymous/3917294 to your computer and use it in GitHub Desktop.
Save anonymous/3917294 to your computer and use it in GitHub Desktop.
ajax delete issue
destroy.js.erb
$('#<%= dom_id(@match) %>').fadeOut();
matches_controller.rb
def destroy
@match = Match.find(params[:id])
@match.destroy
# redirect_to team_matches_url, :notice => "Match Deleted"
respond_to do |format|
format.html { redirect_to team_matches_url, :notice => "Match Deleted" }
format.json { head :ok }
format.js
end
end
index.html.erb
<table>
<tr>
<th>Enemy Team</th>
<th>Date</th>
<th>Shift</th>
<th></th>
<th></th>
</tr>
<% @matches.each do |match| %>
<%= div_for match do %>
<tr>
<% if match.team_id == session[:team_id] %>
<td><%= match.enemy_team_id %></td>
<% else %>
<td><%= match.team_id %></td>
<% end %>
<td><%= match.date %></td>
<td><%= match.shift %></td>
<td><%= link_to 'Edit', edit_team_match_path(@team, match) %></td>
<td><%= link_to 'Destroy', [@team, match], method: :delete, remote: true %></td>
</tr>
<% end %>
<% end %>
</table>
<%= link_to "New Match", new_team_match_path(@current_team) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment