wintermeyer
I have a minimal Ash, PostgreSQL and Phoenix setup in which I do a
mix phx.gen.html Shop Product products name:string price:float --no-context
Obviously the controller doesn’t work out of the box. With some minor changes it works for
index, show and delete.
lib/app_web/controllers/product_controller.ex:
defmodule AppWeb.ProductController do
use AppWeb, :controller
# alias App.Shop
alias App.Shop.Product
def index(conn, _params) do
products = Product.read!()
render(conn, :index, products: products)
end
# def new(conn, _params) do
# changeset = Shop.change_product(%Product{})
# render(conn, :new, changeset: changeset)
# end
# def create(conn, %{"product" => product_params}) do
# case Shop.create_product(product_params) do
# {:ok, product} ->
# conn
# |> put_flash(:info, "Product created successfully.")
# |> redirect(to: ~p"/products/#{product}")
# {:error, %Ecto.Changeset{} = changeset} ->
# render(conn, :new, changeset: changeset)
# end
# end
def show(conn, %{"id" => id}) do
product = Product.by_id!(id)
render(conn, :show, product: product)
end
# def edit(conn, %{"id" => id}) do
# product = Shop.get_product!(id)
# changeset = Shop.change_product(product)
# render(conn, :edit, product: product, changeset: changeset)
# end
# def update(conn, %{"id" => id, "product" => product_params}) do
# product = Product.by_id!(id)
#
# case Product.update(product, product_params) do
# {:ok, product} ->
# conn
# |> put_flash(:info, "Product updated successfully.")
# |> redirect(to: ~p"/products/#{product}")
# {:error, %Ecto.Changeset{} = changeset} ->
# render(conn, :edit, product: product, changeset: changeset)
# end
#end
def delete(conn, %{"id" => id}) do
product = Product.by_id!(id)
:ok = Product.destroy(product)
conn
|> put_flash(:info, "Product deleted successfully.")
|> redirect(to: ~p"/products")
end
end
Is it possible to change the other functions (how?) so that I don’t have to change the forms or do I always have to change the forms too?
For context:
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
barnabasJ
ash_phoenixhasmix ash_phoenix.gen.live. I think this might be what you are looking for.wintermeyer
I would like to know if this can be “fixed” in the controller only or if the views have to be changed too.
barnabasJ
Oh, I misunderstood. As long as you return the same data as before, it will work. I only use the API part of Phoenix, so I’m unfamiliar with this layer. Still, I’m guessing from the code that I see here that you will probably run into problems with the changeset because the HTML generated from Phoenix probably expects normal Ecto Changesets, and you would have to do a lot yourself to handle all of this.
zachdaniel
Yep. You would need to switch to use
AshPhoenix.Form.zachdaniel
Something like:
wintermeyer
How would the template look like?
Given:
I tried this for
edit.html.eexWhich results into this error:
zachdaniel
Ah right you need to call
to_formon the ash form in newer phoenix versionswintermeyer
I can’t find
to_formin the documentation and don’t know how to use it.<.simple_form to_form={@form}>doesn’t work. How do I have to add it?zachdaniel
Like
AshPhoenix.Form.for_create(…) |> to_form()this is what you have to do in live view at least if you got the same error there.Come to think of it, the issue might actually be this:
You should be using the phoenix form when accessing the field.
wintermeyer
That leads to a problem with the update function. Here’s the code:
The controller
The template
The form is displayed. When I click on “Save Product” I get this error:
no function clause matching in AppWeb.ProductController.update/2