Push_patch - how do I translate this using the new routes system?

https://fullstackphoenix.com/tutorials/table-sorting-with-ecto-and-liveview

Sorry if this is obvious but I can’t find any examples anywhere

The guide above has this line

 {:noreply, socket
   |> push_patch(to: Routes.product_index_path(socket, :index, apply_changes(changeset)))
      }

Question 1.

How do I translate this using the new routes system?
No matter how I try to add the apply_changes it will throw an error due to syntax, but I can’t find any examples of how to write this correctly.

{:noreply, push_patch(socket, to: ~p"/some/path")}

I’m not sure where the :index is inside of the product_index_path/3 function. But you should be able to see what the route looks like. You can then do something like

changes = apply_changes(changeset)

path = ~p"/foo/#{changes.id}/bar"

if you need to put a value inside the route. Or you can use

path = ~p"/foo/bar?#{[index: changes.id]}"

if you need it to be a get parameter after the URL.

2 Likes

Managed to find a solution to my issue so thanks for this.