From 2a89bf2e6cbd9eaa98143a38437b063c8c73aa96 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 28 Feb 2018 11:53:43 +0800 Subject: [PATCH] Refactor reportable_url helper to focus on just the title choices. --- app/helpers/issues_helper.rb | 25 ++++++++++++------------- app/views/issues/index.html.erb | 2 +- app/views/issues/show.html.erb | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index b0e598d70..456507d4c 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -15,19 +15,18 @@ module IssuesHelper end end - def reports_url(issue) - class_name = issue.reportable.class.name - case class_name - when "DiaryEntry" - link_to issue.reportable.title, issue - when "User" - link_to issue.reportable.display_name.to_s, issue - when "DiaryComment" - link_to "#{issue.reportable.diary_entry.title}, Comment id ##{issue.reportable.id}", issue - when "Changeset" - link_to "Changeset ##{issue.reportable.id}", issue - when "Note" - link_to "Note ##{issue.reportable.id}", issue + def reportable_title(reportable) + case reportable + when DiaryEntry + reportable.title + when User + reportable.display_name + when DiaryComment + "#{reportable.diary_entry.title}, Comment id ##{reportable.id}" + when Changeset + "Changeset ##{reportable.id}" + when Note + "Note ##{reportable.id}" end end diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 653cd462e..c5e83dce8 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -37,7 +37,7 @@ <%= issue.reports_count %> <%= l(issue.updated_at.to_datetime, :format => :friendly) %> <% if issue.user_updated %> <%= issue.user_updated.display_name %> <% else %> - <% end %> - <%= reports_url(issue) %> + <%= link_to reportable_title(issue.reportable), issue %> <%= link_to issue.reported_user.display_name , :controller => :user, :action => :view, :display_name => issue.reported_user.display_name %> <%= instance_url(issue.reportable) %> diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 05ce1b9f1..fa8afa233 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -46,7 +46,7 @@ <% if @related_issues.count > 1 %> <% @related_issues.each do |issue| %> <% if issue.id != @issue.id %> - <%= reports_url(issue) %>
+ <%= link_to reportable_title(issue.reportable), issue %>
<% end %> <% end %> <% else %> -- 2.43.2