0
這是我第一天嘗試AJAX和jQuery,所以我仍然有點基礎知識。Rails的AJAX/jQuery,需要幫助得到一個div更新
我在this site找到了很多我的代碼。
在銷燬對象時,我希望更新索引頁上的對象列表。
控制器動作:
def destroy
@artist = Artist.find(params[:id])
@artist.destroy
@artists = Artist.all
end
destroy.js.erb:
$("#post_errors").hide(300);
$("#flash_notice").html("<%= escape_javascript(flash[:notice]) %>");
$("#flash_notice").show(300);
$("#posts_list").html("<%= escape_javascript(render(partial: "list")) %>");
_list.html.erb:
<% for artist in @artists %>
<tr>
<td><%= artist.display_name %></td>
<td><%= link_to "Destroy", artist, remote: true, confirm: "Are you sure?", method: :delete %></td>
</tr>
<% end %>
index.html.erb:
<div id="artist_list"><%= render partial: 'list' %></div>
單擊銷燬鏈接時,會執行銷燬該對象的數據庫操作,並刪除該對象,但如果沒有我刷新頁面,索引頁上的列表就不會更新。
有沒有什麼明顯的我在這裏做錯了?
Gah。是。在這裏,以下教程的問題太緊密,不能修改我自己的代碼。非常感謝。 – bdx