Guest User

Untitled

a guest
Jun 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. class BudgetItemsController < InheritedResources::Base
  2. load_and_authorize_resource
  3. respond_to :html, :json
  4.  
  5. before_filter :get_statistics, :only => [:index]
  6. layout 'application', :except => [:edit, :update, :create]
  7.  
  8. def index
  9. @new_budget_item = BudgetItem.new
  10. super
  11. end
  12.  
  13. def create
  14. create! do |format|
  15. if @budget_item.errors.empty?
  16. format.html do
  17. render :show
  18. end
  19. end
  20. end
  21. end
  22.  
  23. def update
  24. update! do |format|
  25. if @budget_item.errors.empty?
  26. format.html { render :show }
  27. end
  28. end
  29. end
  30.  
  31. protected
  32.  
  33. def begin_of_association_chain
  34. current_user
  35. end
  36.  
  37. def get_statistics
  38. @statistics = {
  39. :total_budget => current_user.budget_items.sum(:max_price),
  40. :spendings => current_user.budget_items.sum(:real_price),
  41. :overhead => current_user.budget_items.sum(:real_price) - current_user.budget_items.sum(:max_price)
  42. }
  43. end
  44. end
Add Comment
Please, Sign In to add comment