don't allow empty group titles
This commit is contained in:
parent
9c1bbbbf23
commit
0ced9df13a
@ -54,15 +54,22 @@ defmodule FrenzyWeb.GroupController do
|
||||
|
||||
def create(conn, %{"group" => %{"title" => title}}) do
|
||||
user = conn.assigns[:user]
|
||||
title = title |> String.trim()
|
||||
|
||||
changeset =
|
||||
Ecto.build_assoc(user, :groups, %{
|
||||
title: title
|
||||
})
|
||||
if String.length(title) > 0 do
|
||||
changeset =
|
||||
Ecto.build_assoc(user, :groups, %{
|
||||
title: title
|
||||
})
|
||||
|
||||
{:ok, group} = Repo.insert(changeset)
|
||||
{:ok, group} = Repo.insert(changeset)
|
||||
|
||||
redirect(conn, to: Routes.group_path(Endpoint, :show, group.id))
|
||||
redirect(conn, to: Routes.group_path(Endpoint, :show, group.id))
|
||||
else
|
||||
conn
|
||||
|> put_flash(:error, "Group title must not be empty")
|
||||
|> redirect(to: Routes.group_path(Endpoint, :new))
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, _params) do
|
||||
|
Loading…
x
Reference in New Issue
Block a user