Files
nairobi/app/components/polls/poll_component.rb
2025-08-22 13:12:10 +02:00

25 lines
623 B
Ruby

class Polls::PollComponent < ApplicationComponent
attr_reader :poll
use_helpers :can?
def initialize(poll)
@poll = poll
end
private
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