From b00ddfc931a2dbb64f7c4c5270565bb9af54e03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 22 Oct 2024 23:23:10 +0200 Subject: [PATCH] Move helper method to the component --- app/components/polls/poll_component.rb | 12 +++++++++++- app/helpers/polls_helper.rb | 10 ---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/components/polls/poll_component.rb b/app/components/polls/poll_component.rb index 32b8b0b17..af70041d7 100644 --- a/app/components/polls/poll_component.rb +++ b/app/components/polls/poll_component.rb @@ -1,6 +1,6 @@ class Polls::PollComponent < ApplicationComponent attr_reader :poll - use_helpers :link_to_poll + use_helpers :can? def initialize(poll) @poll = poll @@ -11,4 +11,14 @@ class Polls::PollComponent < ApplicationComponent def dates 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 + else + link_to text, poll_path(id: poll.slug || poll.id), options + end + end end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index b6cadd423..9705c3fda 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -4,16 +4,6 @@ module PollsHelper booth.name + location 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 - else - link_to text, poll_path(id: poll.slug || poll.id), options - end - end - def results_menu? controller_name == "polls" && action_name == "results" end