mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Clean up poll validation
This commit is contained in:
parent
3ff083f157
commit
3366182557
3 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue