Created
February 28, 2018 19:29
-
-
Save amiedes/74fff20338d6d230507b9e45d8a9c698 to your computer and use it in GitHub Desktop.
refactor method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def next_poll(current_site, current_user, poll_id = nil) | |
poll = GobiertoParticipation::Poll.by_site(current_site).find(poll_id) if poll_id | |
answerable_polls = GobiertoParticipation::Poll.by_site(current_site).answerable.order(ends_at: :asc) | |
answerable_polls_by_user = answerable_polls.detect { |p| p.answerable_by?(current_user) } if current_user | |
if current_user | |
if poll && poll.answerable_by?(current_user) | |
poll | |
elsif answerable_polls_by_user | |
answerable_polls_by_user | |
end | |
else | |
if poll | |
poll | |
else | |
answerable_polls.first | |
end | |
end | |
rescue ActiveRecord::RecordNotFound | |
return "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment