Doesn't set form method :put for edit controller action
The documentation sais that form method is set automatically but I have edit action in the controller:
def edit(conn, %{"id" => id}) do
resume = Hr.get_resume!(id)
form = create_form(ResumeType, resume)
IO.inspect form.struct.id
IO.inspect form.method
render(conn, "edit.html", resume: resume, form: form)
end
And in the console it gives me form.struct.id=1 and form.method=nil and of course the form is sent by post method and is rejected by the router.
For now I add the method :put to the form manually:
form = %{form | method: :put}
It helps but why it's not set automatically?
Same here, after some debugging it seems that the builder inside formex_ecto isnt called.
Sorry for waiting so long, I forget about this issue. Thanks @reneweteling for posting.
Are you sure that the builder from formex_ecto isn't called? Maybe there is another problem. In this builder there is:
method = if form.struct.id, do: :put, else: :post
Maybe you don't have an id field or it's empty?
I have checked this on my dev project and I have no problem:
def edit(conn, %{"id" => id}) do
category = Repo.get!(Category, id)
form = create_form(App.CategoryType, category)
IO.inspect form.struct.id
IO.inspect form.method # <---------- :put
render(conn, "edit.html", category: category, form: form)
end
Generated HTML:
<form accept-charset="UTF-8" action="/categories/1" method="post">
<input name="_method" type="hidden" value="put">
...
It sends POST with hidden value _method = put
[info] POST /categories/1