Files
nairobi/app/controllers/admin/budget_groups_controller.rb
rgarcia 86e4a5d853 Find group inside budget
We were having a problem were some groups where not updating correctly.

That was because it was finding the first group with that name. However
we were looking for another group with the same name from another budget

Apart from the group_id, we also get the budget_id in the params for
updating a group. By finding groups within that budget we get the
expected behaviour
2018-03-22 10:19:43 +01:00

27 lines
613 B
Ruby

class Admin::BudgetGroupsController < Admin::BaseController
include FeatureFlags
feature_flag :budgets
def create
@budget = Budget.find params[:budget_id]
@budget.groups.create(budget_group_params)
@groups = @budget.groups.includes(:headings)
end
def update
@group = @budget.groups.by_slug(params[:id]).first
@group.update(budget_group_params)
end
private
def budget_group_params
params.require(:budget_group).permit(:name)
end
def load_budget
@budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
end
end