Use polymorphic paths for milestones
This commit is contained in:
@@ -4,20 +4,20 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||
before_action :load_budget_investment, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||
before_action :load_milestone, only: [:edit, :update, :destroy]
|
||||
before_action :load_statuses, only: [:index, :new, :create, :edit, :update]
|
||||
helper_method :milestoneable_path
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def new
|
||||
@milestone = Milestone.new
|
||||
@milestone = @investment.milestones.new
|
||||
end
|
||||
|
||||
def create
|
||||
@milestone = Milestone.new(milestone_params)
|
||||
@milestone.milestoneable = @investment
|
||||
if @milestone.save
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
|
||||
notice: t('admin.milestones.create.notice')
|
||||
redirect_to milestoneable_path, notice: t('admin.milestones.create.notice')
|
||||
else
|
||||
render :new
|
||||
end
|
||||
@@ -28,8 +28,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||
|
||||
def update
|
||||
if @milestone.update(milestone_params)
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
|
||||
notice: t('admin.milestones.update.notice')
|
||||
redirect_to milestoneable_path, notice: t('admin.milestones.update.notice')
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
@@ -37,8 +36,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||
|
||||
def destroy
|
||||
@milestone.destroy
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
|
||||
notice: t('admin.milestones.delete.notice')
|
||||
redirect_to milestoneable_path, notice: t('admin.milestones.delete.notice')
|
||||
end
|
||||
|
||||
private
|
||||
@@ -73,4 +71,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||
@statuses = Milestone::Status.all
|
||||
end
|
||||
|
||||
def milestoneable_path
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(@milestone.milestoneable)])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<%= render "admin/shared/globalize_locales", resource: @milestone %>
|
||||
|
||||
<%= translatable_form_for [:admin, @investment.budget, @investment, @milestone] do |f| %>
|
||||
<%= translatable_form_for [:admin, *resource_hierarchy_for(@milestone)] do |f| %>
|
||||
|
||||
<div class="small-12 medium-6 margin-bottom">
|
||||
<%= f.select :status_id,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to admin_budget_budget_investment_path(@investment.budget, @investment) %>
|
||||
<%= back_link_to milestoneable_path %>
|
||||
|
||||
<h2><%= t("admin.milestones.edit.title") %></h2>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="milestone-new row">
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= back_link_to admin_budget_budget_investment_path(@investment.budget, @investment) %>
|
||||
<%= back_link_to milestoneable_path %>
|
||||
|
||||
<h1><%= t("admin.milestones.new.creating") %></h1>
|
||||
|
||||
|
||||
@@ -18,9 +18,8 @@
|
||||
<td class="text-center"><%= milestone.id %></td>
|
||||
<td>
|
||||
<%= link_to milestone.title,
|
||||
edit_admin_budget_budget_investment_milestone_path(@investment.budget,
|
||||
@investment,
|
||||
milestone) %>
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(milestone)],
|
||||
action: :edit) %>
|
||||
</td>
|
||||
<td class="small small-5"><%= milestone.description %></td>
|
||||
<td class="small">
|
||||
@@ -46,9 +45,7 @@
|
||||
</td>
|
||||
<td class="small-2">
|
||||
<%= link_to t("admin.milestones.index.delete"),
|
||||
admin_budget_budget_investment_milestone_path(@investment.budget,
|
||||
@investment,
|
||||
milestone),
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(milestone)]),
|
||||
method: :delete,
|
||||
class: "button hollow alert expanded" %>
|
||||
</td>
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
|
||||
<p>
|
||||
<%= link_to t("admin.budget_investments.show.new_milestone"),
|
||||
new_admin_budget_budget_investment_milestone_path(@budget, @investment),
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(@investment.milestones.new)],
|
||||
action: :new),
|
||||
class: "button hollow" %>
|
||||
</p>
|
||||
|
||||
@@ -8,7 +8,7 @@ module ActionDispatch::Routing::UrlFor
|
||||
when "Budget::Investment"
|
||||
[resource.budget, resource]
|
||||
when "Milestone"
|
||||
[resource.milestoneable.budget, resource.milestoneable, resource]
|
||||
[*resource_hierarchy_for(resource.milestoneable), resource]
|
||||
when "Legislation::Annotation"
|
||||
[resource.draft_version.process, resource.draft_version, resource]
|
||||
when "Legislation::Proposal", "Legislation::Question", "Legislation::DraftVersion"
|
||||
|
||||
Reference in New Issue
Block a user