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
27 lines
613 B
Ruby
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
|