Changes suggested in the PR made
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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("<td colspan='4'><%= j render("admin/budgets/heading", group: @budget_group, budget: @budget, heading: @heading) %></td>");
|
||||
<% end %>
|
||||
$("#<%= dom_id(@budget_group) %>").html('<%= j render("admin/budgets/group", group: @budget_group, headings: @budget_group.headings) %>');
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<%= form_for [:admin, budget, group, heading], remote: true do |f| %>
|
||||
<%= render 'shared/errors', resource: heading %>
|
||||
<label><%= t("admin.budgets.form.heading") %></label>
|
||||
<%= f.text_field :name,
|
||||
label: false,
|
||||
@@ -25,6 +26,4 @@
|
||||
</div>
|
||||
|
||||
<%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %>
|
||||
|
||||
<div id="error_explanation"></div>
|
||||
<% end %>
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user