Hey guys
Sorry if this question is dumb but I’m trying to give Phoenix 1.7rc a whirl and I simply can’t get this working.
I have created a new project using mix phx.new
and also ran mix phx.gen.html Todo Item items text:string person_id:integer status:integer
- this is just to create a Todo item.
My file directory now looks like this (I’ve omitted lots of files for simplicity sake):
app_web
- components
- controllers
- item_html
. edit.html.heex
. index.html.heex
. new.html.heex
. show.html.heex
- page_html
. item_controller.ex
. item_html.ex
What I wish to do
new.html.heex
has a simple form. I just want to embed it in index.html.heex
.
In previous versions, this was possible by using the following line in index.html.heex
:
<%= render "new.html", Map.put(assigns, :action, Routes.item_path(@conn, :create)) %>
But in this new version of Phoenix 1.7rc, I simply can’t get this to work
What I tried
I scoured the documentation but I can’t get this to work properly.
I tried another approach, as well.
The item_controller.ex
has many pre-built functions (create, edit, show) which relate to different operations I can do on the created Todo
model I previously generated. The new/2
function pertains to the function that handles whenever I want to create a new Todo (it uses the new.html.heex
file as template).
def new(conn, _params) do
changeset = Todo.change_item(%Item{})
render(conn, :new, changeset: changeset)
end
Since the new.html.heex
is used with this function, I thought that I could just use the following piece of code inside index.html.heex
file and it would render the form.
<%= AppWeb.ItemController.new(@conn, nil) %>
and it would render the form embedded. But it doesn’t! It just renders the form and “forgets” about the rest of the file.
I’m quite at a loss at what I’m missing here.
I hope I was clear and thank you for your attention!