From 50759774f64cd4fd659059b32a40b0d21201c727 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 4 Dec 2019 08:27:35 -0500 Subject: [PATCH] fix conversation controller --- lib/philomena/conversations/conversation.ex | 1 + lib/philomena_web/controllers/conversation_controller.ex | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/philomena/conversations/conversation.ex b/lib/philomena/conversations/conversation.ex index 6e423ac2..19f05266 100644 --- a/lib/philomena/conversations/conversation.ex +++ b/lib/philomena/conversations/conversation.ex @@ -48,6 +48,7 @@ defmodule Philomena.Conversations.Conversation do |> set_slug() |> set_last_message() |> cast_assoc(:messages, with: {Message, :creation_changeset, [from]}) + |> validate_length(:messages, is: 1) end defp set_slug(changeset) do diff --git a/lib/philomena_web/controllers/conversation_controller.ex b/lib/philomena_web/controllers/conversation_controller.ex index 047d9cb7..7fcccc7a 100644 --- a/lib/philomena_web/controllers/conversation_controller.ex +++ b/lib/philomena_web/controllers/conversation_controller.ex @@ -62,11 +62,7 @@ defmodule PhilomenaWeb.ConversationController do render(conn, "new.html", changeset: changeset) end - # Somewhat annoying, cast_assoc has no "limit" validation so we force it - # here to require exactly 1 - def create(conn, %{"conversation" => %{"messages" => %{"0" => message_params} = messages_params} = conversation_params}) - when %{"0" => message_params} == messages_params - do + def create(conn, %{"conversation" => conversation_params}) do user = conn.assigns.current_user case Conversations.create_conversation(user, conversation_params) do