我敢肯定,我在這裏失去了一些東西,但無法弄清楚儘管我所有的搜索。坑正根據我的日誌刪除,但頁面上沒有任何反應。我必須手動刷新頁面才能顯示所做的更改。我是新手,在我的應用程序中使用JS,所以這是我第一次使用它。謝謝。AJAX刪除工作,但不能重新加載頁面
我的日誌說,這
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)
索引視圖
<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>
控制器動作
def destroy
@pit.destroy
end
destroy.js.erb
$('.pits').html("<%= j (render @pits);
'$('。pits')。html(「<%= j(render @pits);'似乎不完整的代碼.. – RAJ 2014-09-01 05:28:33
可能是這樣的。我當時正在使用本教程作爲一個指南 - http://www.gotealeaf.com/blog/the-detailed-guide-on-how-ajax-works-with-ruby -on-rails – 2014-09-01 05:29:42
我從來沒有在之前添加過這樣的內容,因此目前 – 2014-09-01 05:30:12