Simplify uses of polymorphic admin nested routes

This commit is contained in:
Javi Martín
2020-03-16 15:41:48 +01:00
parent 59f70641cb
commit 334b57501b
11 changed files with 20 additions and 20 deletions

View File

@@ -67,6 +67,6 @@ class Admin::MilestonesController < Admin::BaseController
end end
def milestoneable_path def milestoneable_path
polymorphic_path([:admin, *resource_hierarchy_for(@milestone.milestoneable)]) admin_polymorphic_path(@milestone.milestoneable)
end end
end end

View File

@@ -64,6 +64,6 @@ class Admin::ProgressBarsController < Admin::BaseController
end end
def progress_bars_index def progress_bars_index
polymorphic_path([:admin, *resource_hierarchy_for(@progressable), ProgressBar.new]) admin_polymorphic_path(@progressable.progress_bars.new)
end end
end end

View File

@@ -35,7 +35,7 @@
</td> </td>
<td> <td>
<%= link_to t("shared.show"), <%= link_to t("shared.show"),
polymorphic_path([:admin, *resource_hierarchy_for(audit)]), admin_polymorphic_path(audit),
class: "button hollow primary" %> class: "button hollow primary" %>
</td> </td>
</tr> </tr>

View File

@@ -1,7 +1,7 @@
<% provide(:title) do %> <% provide(:title) do %>
<%= t("admin.audits.title") %> <%= t("admin.audits.title") %>
<% end %> <% end %>
<%= back_link_to polymorphic_path([:admin, *resource_hierarchy_for(@audit.associated || @audit.auditable)]) %> <%= back_link_to admin_polymorphic_path(@audit.associated || @audit.auditable) %>
<h2><%= t("admin.audits.title") %></h2> <h2><%= t("admin.audits.title") %></h2>

View File

@@ -1,6 +1,6 @@
<%= render "shared/globalize_locales", resource: @milestone %> <%= render "shared/globalize_locales", resource: @milestone %>
<%= translatable_form_for [:admin, *resource_hierarchy_for(@milestone)] do |f| %> <%= translatable_form_for @milestone, url: admin_polymorphic_path(@milestone) do |f| %>
<div class="row"> <div class="row">
<div class="small-12 medium-6 margin-bottom column"> <div class="small-12 medium-6 margin-bottom column">

View File

@@ -1,7 +1,7 @@
<h2 class="inline-block"><%= t("admin.milestones.index.milestone") %></h2> <h2 class="inline-block"><%= t("admin.milestones.index.milestone") %></h2>
<%= link_to t("admin.progress_bars.manage"), <%= link_to t("admin.progress_bars.manage"),
polymorphic_path([:admin, *resource_hierarchy_for(milestoneable.progress_bars.new)]), admin_polymorphic_path(milestoneable.progress_bars.new),
class: "button hollow float-right" %> class: "button hollow float-right" %>
<% if milestoneable.milestone_tag_list.any? %> <% if milestoneable.milestone_tag_list.any? %>
@@ -31,9 +31,7 @@
<tr id="<%= dom_id(milestone) %>" class="milestone"> <tr id="<%= dom_id(milestone) %>" class="milestone">
<td class="text-center"><%= milestone.id %></td> <td class="text-center"><%= milestone.id %></td>
<td> <td>
<%= link_to milestone.title, <%= link_to milestone.title, admin_polymorphic_path(milestone, action: :edit) %>
polymorphic_path([:admin, *resource_hierarchy_for(milestone)],
action: :edit) %>
</td> </td>
<td class="small small-5"><%= milestone.description %></td> <td class="small small-5"><%= milestone.description %></td>
<td class="small"> <td class="small">
@@ -59,7 +57,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"),
polymorphic_path([:admin, *resource_hierarchy_for(milestone)]), admin_polymorphic_path(milestone),
method: :delete, method: :delete,
class: "button hollow alert expanded" %> class: "button hollow alert expanded" %>
</td> </td>
@@ -73,7 +71,6 @@
<p> <p>
<%= link_to t("admin.milestones.index.new_milestone"), <%= link_to t("admin.milestones.index.new_milestone"),
polymorphic_path([:admin, *resource_hierarchy_for(milestoneable.milestones.new)], admin_polymorphic_path(milestoneable.milestones.new, action: :new),
action: :new),
class: "button hollow" %> class: "button hollow" %>
</p> </p>

View File

@@ -1,6 +1,6 @@
<%= render "shared/globalize_locales", resource: @progress_bar %> <%= render "shared/globalize_locales", resource: @progress_bar %>
<%= translatable_form_for [:admin, *resource_hierarchy_for(@progress_bar)] do |f| %> <%= translatable_form_for @progress_bar, url: admin_polymorphic_path(@progress_bar) do |f| %>
<div class="row"> <div class="row">
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">

View File

@@ -1,8 +1,8 @@
<h2 class="inline-block"><%= t("admin.progress_bars.index.title") %></h2> <h2 class="inline-block"><%= t("admin.progress_bars.index.title") %></h2>
<%= link_to t("admin.progress_bars.index.new_progress_bar"), <%= link_to t("admin.progress_bars.index.new_progress_bar"),
polymorphic_path( admin_polymorphic_path(
[:admin, *resource_hierarchy_for(ProgressBar.new(progressable: progressable))], ProgressBar.new(progressable: progressable),
action: :new action: :new
), ),
class: "button float-right" %> class: "button float-right" %>
@@ -37,12 +37,11 @@
</td> </td>
<td> <td>
<%= link_to t("admin.actions.edit"), <%= link_to t("admin.actions.edit"),
polymorphic_path([:admin, *resource_hierarchy_for(progress_bar)], admin_polymorphic_path(progress_bar, action: :edit),
action: :edit),
class: "button hollow" %> class: "button hollow" %>
<%= link_to t("admin.actions.delete"), <%= link_to t("admin.actions.delete"),
polymorphic_path([:admin, *resource_hierarchy_for(progress_bar)]), admin_polymorphic_path(progress_bar),
method: :delete, method: :delete,
class: "button hollow alert" %> class: "button hollow alert" %>
</td> </td>

View File

@@ -2,7 +2,7 @@
<%= "#{t("admin.header.title")} - #{t("admin.progress_bars.index.title")}" %> <%= "#{t("admin.header.title")} - #{t("admin.progress_bars.index.title")}" %>
<% end %> <% end %>
<%= back_link_to polymorphic_path([:admin, *resource_hierarchy_for(@progressable)]) %> <%= back_link_to admin_polymorphic_path(@progressable) %>
<div class="clear"></div> <div class="clear"></div>

View File

@@ -63,4 +63,8 @@ module ActionDispatch::Routing::UrlFor
polymorphic_path(resources) polymorphic_path(resources)
end end
end end
def admin_polymorphic_path(resource, options = {})
polymorphic_path([:admin, *resource_hierarchy_for(resource)], options)
end
end end

View File

@@ -5,7 +5,7 @@ shared_examples "admin_progressable" do |factory_name, path_name|
let(:progressable_path) { send(path_name, *resource_hierarchy_for(progressable)) } let(:progressable_path) { send(path_name, *resource_hierarchy_for(progressable)) }
let(:path) do let(:path) do
polymorphic_path([:admin, *resource_hierarchy_for(progressable.progress_bars.new)]) admin_polymorphic_path(progressable.progress_bars.new)
end end
context "Index" do context "Index" do