Move helper method to the component

This commit is contained in:
Javi Martín
2024-10-22 23:23:10 +02:00
parent edfea8f06b
commit b00ddfc931
2 changed files with 11 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
class Polls::PollComponent < ApplicationComponent class Polls::PollComponent < ApplicationComponent
attr_reader :poll attr_reader :poll
use_helpers :link_to_poll use_helpers :can?
def initialize(poll) def initialize(poll)
@poll = poll @poll = poll
@@ -11,4 +11,14 @@ class Polls::PollComponent < ApplicationComponent
def dates def dates
t("polls.dates", open_at: l(poll.starts_at.to_date), closed_at: l(poll.ends_at.to_date)) t("polls.dates", open_at: l(poll.starts_at.to_date), closed_at: l(poll.ends_at.to_date))
end 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 end

View File

@@ -4,16 +4,6 @@ module PollsHelper
booth.name + location booth.name + location
end 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? def results_menu?
controller_name == "polls" && action_name == "results" controller_name == "polls" && action_name == "results"
end end