Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BudgetItemsController < InheritedResources::Base
- load_and_authorize_resource
- respond_to :html, :json
- before_filter :get_statistics, :only => [:index]
- layout 'application', :except => [:edit, :update, :create]
- def index
- @new_budget_item = BudgetItem.new
- super
- end
- def create
- create! do |format|
- if @budget_item.errors.empty?
- format.html do
- render :show
- end
- end
- end
- end
- def update
- update! do |format|
- if @budget_item.errors.empty?
- format.html { render :show }
- end
- end
- end
- protected
- def begin_of_association_chain
- current_user
- end
- def get_statistics
- @statistics = {
- :total_budget => current_user.budget_items.sum(:max_price),
- :spendings => current_user.budget_items.sum(:real_price),
- :overhead => current_user.budget_items.sum(:real_price) - current_user.budget_items.sum(:max_price)
- }
- end
- end
Add Comment
Please, Sign In to add comment