From 7473b92309e8bea8366384f153580a723c2799b4 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Tue, 31 Dec 2019 19:54:19 -0500 Subject: [PATCH] fix channel creation errors --- lib/philomena/channels/channel.ex | 7 +++---- lib/philomena_web/templates/channel/new.html.slime | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/philomena/channels/channel.ex b/lib/philomena/channels/channel.ex index f3585cb9..a7136257 100644 --- a/lib/philomena/channels/channel.ex +++ b/lib/philomena/channels/channel.ex @@ -38,10 +38,9 @@ defmodule Philomena.Channels.Channel do @doc false def changeset(channel, attrs) do tag_id = - if attrs["artist_tag"] do - Repo.get_by(Tag, name: attrs["artist_tag"]).id - else - nil + case Repo.get_by(Tag, name: attrs["artist_tag"] || "") do + %{id: id} -> id + _ -> nil end channel diff --git a/lib/philomena_web/templates/channel/new.html.slime b/lib/philomena_web/templates/channel/new.html.slime index f3293068..8a3551e9 100644 --- a/lib/philomena_web/templates/channel/new.html.slime +++ b/lib/philomena_web/templates/channel/new.html.slime @@ -1,3 +1,3 @@ h1 Adding Channel -= render PhilomenaWeb.ChannelView, "_form.html", changeset: @changeset, action: Routes.channel_path(@conn, :new), conn: @conn += render PhilomenaWeb.ChannelView, "_form.html", changeset: @changeset, action: Routes.channel_path(@conn, :create), conn: @conn