我正在使用rails 3和創建支出維護應用程序。 在這個每個條目都有支出金額字段,我正在通過ajax成功添加/刪除/更新它。 但我試圖刷新總金額值,每當添加,刪除編輯操作完成。更新總數入門添加,刪除和更新ajax
看我的代碼:
刪除控制器功能:
def destroy
@expenditure = Expenditure.find(params[:id])
@expenditure.destroy
**@total = Expenditure.where(:user_id => current_user.id).sum('amount')**
//@total calculated and to be updated in view
respond_to do |format|
format.html { redirect_to(@expenditure) }
format.js { head :ok }
end
end
後的支出被刪除我這樣做:
$('.delete_post').live('ajax:success', function() {
$(this).parent().parent().fadeOut();
**$("#totalBox").html("<%= escape_javascript(render(:partial => 'total' , :locals => { :total => expenditures.calculateTotal })).html_safe %>");**
});
索引視圖:
<div class="blocks" id='**totalBox**'>
<%= render :partial => 'total' , :locals => { :total => @total }%>
</div>
總的部分:
Summary
<hr/>
<div class="actionItems">
Total Expenditure <> <span id='totalexp'><%= total %></span>
</div>
在不久的將來,我必須要通過更多的值,以該部分像 上個月的費用, 朋友1費用, FRIEND2費用,
請幫我解決這個問題? 也建議一種方法來解決這種類型的問題? 我是一個新bi- 幫助// SOS
你們是不是要刷新視圖,數據庫,或兩者兼而有之? – yoozer8
問題更新;添加說明 – dbKooper