can't resist
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
830 B

defmodule TomieWeb.TagLive.New do
use TomieWeb, :live
alias Tags.Tag
def render(assigns), do: TomieWeb.TagView.render("new.html", assigns)
def mount(_params, _session, socket) do
changeset = Tag.changeset(%Tag{})
{:ok, socket |> assign(changeset: changeset)}
end
def handle_event("validate", %{"tag" => params}, socket) do
changeset =
%Tag{}
|> Tag.changeset(params)
|> Map.put(:action, :insert)
{:noreply, assign(socket, changeset: changeset)}
end
def handle_event("save", %{"tag" => params}, socket) do
case Tags.create_tag(params) do
{:ok, tag} ->
{:noreply,
push_redirect(socket, to: Routes.live_path(socket, TomieWeb.TagLive.Show, tag))}
{:error, changeset} ->
{:noreply, assign(socket, changeset: changeset)}
end
end
end