私はレール3を使用しており、支出管理アプリケーションを作成しています。 このエントリーには、支出額フィールドがあり、私はajax経由でそれを追加/削除/更新しています。 しかし、追加、削除の編集操作が行われるたびに、合計金額の値を更新しようとしています。私のコードで更新エントリの合計カウントajaxでの追加、削除、更新
ルック:
削除コントローラ機能:
$('.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>
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
支出は、私はこれを行うに削除された後、部分的な合計:私はこの部分のような 先月費、 friend1費用、 friend2費、
に複数の値を渡す必要があり、近い将来には
Summary
<hr/>
<div class="actionItems">
Total Expenditure <> <span id='totalexp'><%= total %></span>
</div>
は私がこの問題を解決する助けてください? このタイプの問題を解決する方法を提案しますか? 私はnew-biです ヘルプ// SOS
format.js
としてそれを残しformat.js
からhead :ok
を削除するだろうあなたは、ビュー、データベース、またはその両方でそれを更新しようとしていますか? – yoozer8質問が更新されました。説明が追加されました – dbKooper