diff --git a/lib/philomena/polls/poll.ex b/lib/philomena/polls/poll.ex index 264e96bb..919a62a1 100644 --- a/lib/philomena/polls/poll.ex +++ b/lib/philomena/polls/poll.ex @@ -39,7 +39,7 @@ defmodule Philomena.Polls.Poll do |> validate_required([:title, :active_until, :vote_method]) |> validate_length(:title, max: 140, count: :bytes) |> validate_inclusion(:vote_method, ["single", "multiple"]) - |> cast_assoc(:options, with: &PollOption.creation_changeset/2) + |> cast_assoc(:options, required: true, with: &PollOption.creation_changeset/2) |> validate_length(:options, min: 2, max: 20) |> ignore_if_blank() end diff --git a/lib/philomena_web/controllers/topic/poll/vote_controller.ex b/lib/philomena_web/controllers/topic/poll/vote_controller.ex index b92f1c54..3af4f011 100644 --- a/lib/philomena_web/controllers/topic/poll/vote_controller.ex +++ b/lib/philomena_web/controllers/topic/poll/vote_controller.ex @@ -51,6 +51,14 @@ defmodule PhilomenaWeb.Topic.Poll.VoteController do end end + def create(conn, _params) do + topic = conn.assigns.topic + + conn + |> put_flash(:error, "Your vote was not recorded.") + |> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic)) + end + def delete(conn, %{"id" => poll_vote_id}) do topic = conn.assigns.topic poll_vote = PollVotes.get_poll_vote!(poll_vote_id) diff --git a/lib/philomena_web/views/topic/poll_view.ex b/lib/philomena_web/views/topic/poll_view.ex index 04801def..b8c88c87 100644 --- a/lib/philomena_web/views/topic/poll_view.ex +++ b/lib/philomena_web/views/topic/poll_view.ex @@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Topic.PollView do def winning_option(poll) do poll |> ranked_options() - |> hd() + |> Enum.at(0) end def active?(poll) do