After extensive searching, I still can't seem to figure out why The Pit is deleting according to my logs but the changes aren't reflected on the page until I manually refresh. This is my first time working with JS in my app so it's a learning process for me. Any insights would be greatly appreciated.
Here's what my log says:
Started DELETE "/pits/25" for 127.0.0.1 at 2014-09-01 00:20:45 -0500
Processing by PitsController#destroy as JS
Parameters: {"id"=>"25"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Pit Load (0.3ms) SELECT "pits".* FROM "pits" WHERE "pits"."user_id" = ? AND "pits"."id" = 25 LIMIT 1 [["user_id", 1]]
(0.1ms) begin transaction
ActsAsVotable::Vote Load (0.1ms) SELECT "votes".* FROM "votes" WHERE "votes"."votable_id" = ? AND "votes"."votable_type" = ? [["votable_id", 25], ["votable_type", "Pit"]]
SQL (28.1ms) DELETE FROM "pits" WHERE "pits"."id" = ? [["id", 25]]
(1.3ms) commit transaction
Rendered pits/destroy.js.erb (0.6ms)
Completed 200 OK in 111ms (Views: 37.7ms | ActiveRecord: 30.2ms)
Index view:
<div class = "container list-pits">
<%= link_to "Add New Pit", new_pit_path, class: "btn btn-default" %>
<br>
<br>
<% @pit.each do |pit| %>
<div class = "container">
<div class = "well pit-index">
<h3 id="pit-title"><%= link_to pit.topic, pit_path(pit) %></h3>
<p>by <%= link_to pit.author, '#' %></p>
<br>
<p><%= pit.summary %></p>
<p>Replies (<%= pit.comments.count %>)</p>
<br>
<p>Pit Created by: <%= link_to pit.user.name, pit.user %> on <%= pit.created_at %></p>
<%= link_to "View Pit", pit_path(pit), class: "btn btn-primary" %>
<%= link_to pit_path(pit), remote: true, method: :delete, data: { confirm: 'Are you sure?' } do %>
<button class = "btn btn-primary">Delete!</button>
<% end %>
</div>
</div>
<% end %>
</div>
Controller Action:
def destroy
@pit.destroy
end
destroy.js.erb:
$('.pits').html("<%= j (render @pits);