diff --git a/app/controllers/admin/budget_headings_controller.rb b/app/controllers/admin/budget_headings_controller.rb index ee1878edf..902f256b5 100644 --- a/app/controllers/admin/budget_headings_controller.rb +++ b/app/controllers/admin/budget_headings_controller.rb @@ -3,30 +3,30 @@ class Admin::BudgetHeadingsController < Admin::BaseController feature_flag :budgets def create - @budget = Budget.find params[:budget_id] - @budget_group = @budget.groups.find params[:budget_group_id] + @budget = Budget.find(params[:budget_id]) + @budget_group = @budget.groups.find(params[:budget_group_id]) @budget_group.headings.create(budget_heading_params) @headings = @budget_group.headings end def edit - @budget = Budget.find params[:budget_id] - @budget_group = @budget.groups.find params[:budget_group_id] - @heading = Budget::Heading.find params[:id] + @budget = Budget.find(params[:budget_id]) + @budget_group = @budget.groups.find(params[:budget_group_id]) + @heading = Budget::Heading.find(params[:id]) end def update - @budget = Budget.find params[:budget_id] - @budget_group = @budget.groups.find params[:budget_group_id] - @heading = Budget::Heading.find params[:id] + @budget = Budget.find(params[:budget_id]) + @budget_group = @budget.groups.find(params[:budget_group_id]) + @heading = Budget::Heading.find(params[:id]) @heading.assign_attributes(budget_heading_params) - @errors = @heading.errors.full_messages unless @heading.save + render :edit unless @heading.save end def destroy - @heading = Budget::Heading.find params[:id] + @heading = Budget::Heading.find(params[:id]) @heading.destroy - @budget = Budget.find params[:budget_id] + @budget = Budget.find(params[:budget_id]) redirect_to admin_budget_path(@budget) end diff --git a/app/views/admin/budget_headings/update.js.erb b/app/views/admin/budget_headings/update.js.erb index d46e35386..6466959cd 100644 --- a/app/views/admin/budget_headings/update.js.erb +++ b/app/views/admin/budget_headings/update.js.erb @@ -1,5 +1 @@ -<% if @errors %> - $("#heading-<%=@heading.id%> div#error_explanation").replaceWith("<%= j render("admin/budget_headings/errors", errors: @errors) %>"); -<% else %> - $("#heading-<%=@heading.id%>").html("<%= j render("admin/budgets/heading", group: @budget_group, budget: @budget, heading: @heading) %>"); -<% end %> +$("#<%= dom_id(@budget_group) %>").html('<%= j render("admin/budgets/group", group: @budget_group, headings: @budget_group.headings) %>'); diff --git a/app/views/admin/budgets/_heading.html.erb b/app/views/admin/budgets/_heading.html.erb index 7ffeca7a0..bc9d59c5f 100644 --- a/app/views/admin/budgets/_heading.html.erb +++ b/app/views/admin/budgets/_heading.html.erb @@ -12,16 +12,16 @@ <%= link_to t("admin.actions.edit"), edit_admin_budget_budget_group_budget_heading_path(budget_id: group.budget.id, budget_group_id: group.id, id: heading.id), class: "button hollow", - remote: true%> + remote: true %> <%= link_to t("admin.budget_investments.index.title"), admin_budget_budget_investments_path(budget_id: group.budget.id, heading_id: heading.id), - class: "button hollow"%> + class: "button hollow" %> <% if heading.can_be_deleted? %> <%= link_to t('admin.administrators.administrator.delete'), #admin_budget_budget_group_budget_headings_path(group.budget.id, group.id), [:admin, group.budget, group, heading], method: :delete, - class: "button hollow alert"%> + class: "button hollow alert" %> <% end %> - \ No newline at end of file + diff --git a/app/views/admin/budgets/_heading_form.html.erb b/app/views/admin/budgets/_heading_form.html.erb index 43a4797a8..8dd2d563a 100644 --- a/app/views/admin/budgets/_heading_form.html.erb +++ b/app/views/admin/budgets/_heading_form.html.erb @@ -1,4 +1,5 @@ <%= form_for [:admin, budget, group, heading], remote: true do |f| %> + <%= render 'shared/errors', resource: heading %> <%= f.text_field :name, label: false, @@ -25,6 +26,4 @@ <%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %> - -
-<% end %> \ No newline at end of file +<% end %> diff --git a/spec/models/budget/heading_spec.rb b/spec/models/budget/heading_spec.rb index 76ac82692..a556cf2ca 100644 --- a/spec/models/budget/heading_spec.rb +++ b/spec/models/budget/heading_spec.rb @@ -26,7 +26,7 @@ describe Budget::Heading do end describe "heading" do - it "can be deleted if not budget's investments associated" do + it "can be deleted if no budget's investments associated" do heading1 = create(:budget_heading, group: group, name: 'name') heading2 = create(:budget_heading, group: group, name: 'name 2') @@ -34,7 +34,6 @@ describe Budget::Heading do expect(heading1.can_be_deleted?).to eq false expect(heading2.can_be_deleted?).to eq true - end end