Skip to content

Instantly share code, notes, and snippets.

@amiedes
Created February 28, 2018 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiedes/74fff20338d6d230507b9e45d8a9c698 to your computer and use it in GitHub Desktop.
Save amiedes/74fff20338d6d230507b9e45d8a9c698 to your computer and use it in GitHub Desktop.
refactor method
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