Use polymorphic paths for milestones

This commit is contained in:
Javi Martín
2018-11-12 19:27:14 +01:00
parent 4f9ca04a84
commit 2c2831beb0
7 changed files with 17 additions and 18 deletions

View File

@@ -4,20 +4,20 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
before_action :load_budget_investment, only: [:index, :new, :create, :edit, :update, :destroy] before_action :load_budget_investment, only: [:index, :new, :create, :edit, :update, :destroy]
before_action :load_milestone, only: [:edit, :update, :destroy] before_action :load_milestone, only: [:edit, :update, :destroy]
before_action :load_statuses, only: [:index, :new, :create, :edit, :update] before_action :load_statuses, only: [:index, :new, :create, :edit, :update]
helper_method :milestoneable_path
def index def index
end end
def new def new
@milestone = Milestone.new @milestone = @investment.milestones.new
end end
def create def create
@milestone = Milestone.new(milestone_params) @milestone = Milestone.new(milestone_params)
@milestone.milestoneable = @investment @milestone.milestoneable = @investment
if @milestone.save if @milestone.save
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), redirect_to milestoneable_path, notice: t('admin.milestones.create.notice')
notice: t('admin.milestones.create.notice')
else else
render :new render :new
end end
@@ -28,8 +28,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
def update def update
if @milestone.update(milestone_params) if @milestone.update(milestone_params)
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), redirect_to milestoneable_path, notice: t('admin.milestones.update.notice')
notice: t('admin.milestones.update.notice')
else else
render :edit render :edit
end end
@@ -37,8 +36,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
def destroy def destroy
@milestone.destroy @milestone.destroy
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), redirect_to milestoneable_path, notice: t('admin.milestones.delete.notice')
notice: t('admin.milestones.delete.notice')
end end
private private
@@ -73,4 +71,7 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
@statuses = Milestone::Status.all @statuses = Milestone::Status.all
end end
def milestoneable_path
polymorphic_path([:admin, *resource_hierarchy_for(@milestone.milestoneable)])
end
end end

View File

@@ -1,6 +1,6 @@
<%= render "admin/shared/globalize_locales", resource: @milestone %> <%= 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"> <div class="small-12 medium-6 margin-bottom">
<%= f.select :status_id, <%= f.select :status_id,

View File

@@ -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> <h2><%= t("admin.milestones.edit.title") %></h2>

View File

@@ -1,7 +1,7 @@
<div class="milestone-new row"> <div class="milestone-new row">
<div class="small-12 column"> <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> <h1><%= t("admin.milestones.new.creating") %></h1>

View File

@@ -18,9 +18,8 @@
<td class="text-center"><%= milestone.id %></td> <td class="text-center"><%= milestone.id %></td>
<td> <td>
<%= link_to milestone.title, <%= link_to milestone.title,
edit_admin_budget_budget_investment_milestone_path(@investment.budget, polymorphic_path([:admin, *resource_hierarchy_for(milestone)],
@investment, action: :edit) %>
milestone) %>
</td> </td>
<td class="small small-5"><%= milestone.description %></td> <td class="small small-5"><%= milestone.description %></td>
<td class="small"> <td class="small">
@@ -46,9 +45,7 @@
</td> </td>
<td class="small-2"> <td class="small-2">
<%= link_to t("admin.milestones.index.delete"), <%= link_to t("admin.milestones.index.delete"),
admin_budget_budget_investment_milestone_path(@investment.budget, polymorphic_path([:admin, *resource_hierarchy_for(milestone)]),
@investment,
milestone),
method: :delete, method: :delete,
class: "button hollow alert expanded" %> class: "button hollow alert expanded" %>
</td> </td>

View File

@@ -63,6 +63,7 @@
<p> <p>
<%= link_to t("admin.budget_investments.show.new_milestone"), <%= 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" %> class: "button hollow" %>
</p> </p>

View File

@@ -8,7 +8,7 @@ module ActionDispatch::Routing::UrlFor
when "Budget::Investment" when "Budget::Investment"
[resource.budget, resource] [resource.budget, resource]
when "Milestone" when "Milestone"
[resource.milestoneable.budget, resource.milestoneable, resource] [*resource_hierarchy_for(resource.milestoneable), resource]
when "Legislation::Annotation" when "Legislation::Annotation"
[resource.draft_version.process, resource.draft_version, resource] [resource.draft_version.process, resource.draft_version, resource]
when "Legislation::Proposal", "Legislation::Question", "Legislation::DraftVersion" when "Legislation::Proposal", "Legislation::Question", "Legislation::DraftVersion"