diff --git a/assets/css/app.scss b/assets/css/app.scss
index e30ec01..17afdec 100644
--- a/assets/css/app.scss
+++ b/assets/css/app.scss
@@ -36,6 +36,10 @@ pre.ssh_keys {
}
}
+.invalid-feedback {
+ display: inherit;
+}
+
/* LiveView specific classes for your customization */
.phx-no-feedback.invalid-feedback,
.phx-no-feedback .invalid-feedback {
diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index 76cbb87..936bd2b 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -4,6 +4,7 @@ defmodule KmxgitWeb.RepositoryController do
alias Kmxgit.RepositoryManager
alias Kmxgit.RepositoryManager.Repository
alias Kmxgit.SlugManager
+ alias Kmxgit.Repo
def new(conn, params) do
action = Routes.repository_path(conn, :create, params["owner"])
@@ -65,18 +66,22 @@ defmodule KmxgitWeb.RepositoryController do
end
defp create_repo(conn, owner, params) do
- Repo.transaction do
- case RepositoryManager.create_repository(owner, params) do
- {:ok, repo} ->
- conn
- |> redirect(to: Routes.repository_path(conn, :show, owner.slug.slug, Repository.splat(repo)))
- {:error, changeset} ->
- IO.inspect(changeset)
- conn
- |> assign(:action, Routes.repository_path(conn, :create, owner.slug.slug))
- |> assign(:changeset, changeset)
- |> render("new.html")
- end
+ case Repo.transaction(fn ->
+ case RepositoryManager.create_repository(owner, params) do
+ {:ok, repo} -> {:ok, repo}
+ {:error, changeset} -> Repo.rollback changeset
+ end
+ end) do
+ {:ok, repo} ->
+ conn
+ |> redirect(to: Routes.repository_path(conn, :show, owner.slug.slug, Repository.splat(repo)))
+ {:error, changeset} ->
+ IO.inspect(changeset)
+ conn
+ |> assign(:action, Routes.repository_path(conn, :create, owner.slug.slug))
+ |> assign(:changeset, changeset)
+ |> assign(:owner, owner)
+ |> render("new.html")
end
end
diff --git a/lib/kmxgit_web/templates/repository/form.html.heex b/lib/kmxgit_web/templates/repository/form.html.heex
index 13717bd..1535a36 100644
--- a/lib/kmxgit_web/templates/repository/form.html.heex
+++ b/lib/kmxgit_web/templates/repository/form.html.heex
@@ -1,4 +1,4 @@
-<.form let={f} for={@changeset} action={@action}>
+<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Invalid parameters</p>
@@ -35,4 +35,4 @@
<%= submit gettext("Submit"), class: "btn btn-primary" %>
</div>
-</.form>
+<% end %>