diff --git a/lib/ketbin_web/controllers/page_controller.ex b/lib/ketbin_web/controllers/page_controller.ex index bf07d89..f29262b 100644 --- a/lib/ketbin_web/controllers/page_controller.ex +++ b/lib/ketbin_web/controllers/page_controller.ex @@ -5,11 +5,25 @@ defmodule KetbinWeb.PageController do alias Ketbin.Pastes.Paste def index(conn, _params) do - render(conn, "index.html") + changeset = Pastes.change_paste(%Paste{}) + render(conn, "index.html", changeset: changeset) end def show(conn, %{"id" => id}) do paste = Pastes.get_paste!(id) render(conn, "show.html", paste: paste) end + + def create(conn, %{"paste" => paste_params}) do + # paste_params = Map.put(paste_params, "id", s) + case Pastes.create_paste(paste_params) do + {:ok, paste} -> + conn + |> put_flash(:info, "Paste created successfully.") + |> redirect(to: Routes.paste_path(conn, :show, paste)) + + {:error, %Ecto.Changeset{} = changeset} -> + render(conn, "index.html", changeset: changeset) + end + end end diff --git a/lib/ketbin_web/router.ex b/lib/ketbin_web/router.ex index 42d978a..0af8b63 100644 --- a/lib/ketbin_web/router.ex +++ b/lib/ketbin_web/router.ex @@ -21,6 +21,7 @@ defmodule KetbinWeb.Router do get "/", PageController, :index get "/:id", PageController, :show + post "/", PageController, :create end # Other scopes may use custom stacks. diff --git a/lib/ketbin_web/templates/layout/app.html.eex b/lib/ketbin_web/templates/layout/app.html.eex index 4ab9ab3..ad82c23 100644 --- a/lib/ketbin_web/templates/layout/app.html.eex +++ b/lib/ketbin_web/templates/layout/app.html.eex @@ -11,7 +11,7 @@ -
+Oops, something went wrong!
+