Skip to content

Commit

Permalink
docs: remove incorrect update logic in getting started guide
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 22, 2024
1 parent 9f18c5d commit 862c395
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions documentation/tutorials/getting-started-with-ash-and-phoenix.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ defmodule MyAshPhoenixApp.Blog do
# Define an interface for calling resource actions.
define :create_post, action: :create
define :list_posts, action: :read
define :update_post, action: :update
define :destroy_post, action: :destroy
define :get_post, args: [:id], action: :by_id
end
Expand Down Expand Up @@ -355,13 +354,6 @@ defmodule MyAshPhoenixAppWeb.PostsLive do
<.input type="text" field={f[:title]} placeholder="input title" />
<.button class="mt-2" type="submit">Create</.button>
</.form>
<h2 class="mt-8 text-lg">Update Post</h2>
<.form :let={f} for={@update_form} phx-submit="update_post">
<.label>Post Name</.label>
<.input type="select" field={f[:post_id]} options={@post_selector} />
<.input type="text" field={f[:content]} placeholder="input content" />
<.button class="mt-2" type="submit">Update</.button>
</.form>
"""
end
Expand All @@ -372,8 +364,7 @@ defmodule MyAshPhoenixAppWeb.PostsLive do
assign(socket,
posts: posts,
post_selector: post_selector(posts),
create_form: AshPhoenix.Form.for_create(Post, :create) |> to_form(),
update_form: AshPhoenix.Form.for_update(List.first(posts, %Post{}), :update) |> to_form()
create_form: AshPhoenix.Form.for_create(Post, :create) |> to_form()
)
{:ok, socket}
Expand All @@ -398,18 +389,6 @@ defmodule MyAshPhoenixAppWeb.PostsLive do
end
end
def handle_event("update_post", %{"form" => form_params}, socket) do
case AshPhoenix.Form.submit(socket.assigns.update_form, params: form_params) do
{:ok, _post} ->
posts = Blog.list_posts!()
{:noreply, assign(socket, posts: posts, post_selector: post_selector(posts))}
{:error, update_form} ->
{:noreply, assign(socket, update_form: update_form)}
end
end
defp post_selector(posts) do
for post <- posts do
{post.title, post.id}
Expand Down

0 comments on commit 862c395

Please sign in to comment.