diff --git a/app/components/polls/poll_component.html.erb b/app/components/polls/poll_component.html.erb
index 17002ba0c..917f14366 100644
--- a/app/components/polls/poll_component.html.erb
+++ b/app/components/polls/poll_component.html.erb
@@ -8,13 +8,9 @@
- <% if poll.questions.one? %>
-
<%= link_to_poll poll.questions.first.title, poll %>
-
<%= dates %>
- <% else %>
-
<%= link_to_poll poll.name, poll %>
-
<%= dates %>
-
+
<%= link_to header_text, path %>
+
<%= dates %>
+ <% if poll.questions.many? %>
<% poll.questions.sort_for_list.each do |question| %>
- <%= question.title %>
@@ -25,9 +21,5 @@
<%= render SDG::TagListComponent.new(poll, limit: 5, linkable: false) %>
- <% if poll.expired? %>
- <%= link_to_poll t("polls.index.participate_button_expired"), poll, class: "button hollow expanded" %>
- <% else %>
- <%= link_to_poll t("polls.index.participate_button"), poll, class: "button hollow expanded" %>
- <% end %>
+ <%= link_to link_text, path, class: "button hollow expanded" %>
diff --git a/app/components/polls/poll_component.rb b/app/components/polls/poll_component.rb
index af70041d7..4e7d465de 100644
--- a/app/components/polls/poll_component.rb
+++ b/app/components/polls/poll_component.rb
@@ -12,13 +12,29 @@ class Polls::PollComponent < ApplicationComponent
t("polls.dates", open_at: l(poll.starts_at.to_date), closed_at: l(poll.ends_at.to_date))
end
- def link_to_poll(text, poll, options = {})
- if can?(:results, poll)
- link_to text, results_poll_path(id: poll.slug || poll.id), options
- elsif can?(:stats, poll)
- link_to text, stats_poll_path(id: poll.slug || poll.id), options
+ def header_text
+ if poll.questions.one?
+ poll.questions.first.title
else
- link_to text, poll_path(id: poll.slug || poll.id), options
+ poll.name
+ end
+ end
+
+ def link_text
+ if poll.expired?
+ t("polls.index.participate_button_expired")
+ else
+ t("polls.index.participate_button")
+ end
+ end
+
+ def path
+ if can?(:results, poll)
+ results_poll_path(id: poll.slug || poll.id)
+ elsif can?(:stats, poll)
+ stats_poll_path(id: poll.slug || poll.id)
+ else
+ poll_path(id: poll.slug || poll.id)
end
end
end