Move helper method to the component
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user