0

I created a toy app using Phoenix/LiveView. I used the generators to create things. It's possible I messed with routes. The app is a simple CRUD, list-o-stuff application. Nothing tricky.

I can see the list of sets (my schema/struct). I can open up the modal dialog to add all the information but when I click the button to save it, I get this error:

"no route found for POST /sets/new (TumblingDiceWeb.Router)"

And the stack trace:

 deps/phoenix/lib/phoenix/router.ex:487 TumblingDiceWeb.Router.call/2
 lib/tumbling_dice_web/endpoint.ex:1 TumblingDiceWeb.Endpoint.plug_builder_call/2
 deps/plug/lib/plug/debugger.ex:136 TumblingDiceWeb.Endpoint."call (overridable 3)"/2
 lib/tumbling_dice_web/endpoint.ex:1 TumblingDiceWeb.Endpoint.call/2
 phoenix lib/phoenix/endpoint/sync_code_reload_plug.ex:22 Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
 plug_cowboy lib/plug/cowboy/handler.ex:11 Plug.Cowboy.Handler.init/2
 cowboy /Users/jdkaplan/sources/tumbling_dice/deps/cowboy/src/cowboy_handler.erl:37 :cowboy_handler.execute/2
 cowboy /Users/jdkaplan/sources/tumbling_dice/deps/cowboy/src/cowboy_stream_h.erl:306 :cowboy_stream_h.execute/3
 cowboy /Users/jdkaplan/sources/tumbling_dice/deps/cowboy/src/cowboy_stream_h.erl:295 :cowboy_stream_h.request_process/3
 stdlib proc_lib.erl:240 :proc_lib.init_p_do_apply/3

The error message seems to suggest that I'm not actually submitting via LiveView but by an HTTP Post. I've seen things in other solutions like "clean and rerun npm install" or change the import of such and such. None of these things has worked, but I suspect I'm simply missing something key.

My routes are defined as

  live "/sets", SetLive.Index, :index
  live "/sets/new", SetLive.Index, :new
  live "/sets/:id/edit", SetLive.Index, :edit

  live "/sets/:id", SetLive.Show, :show
  live "/sets/:id/show/edit", SetLive.Show, :edit

In the error message it lists these known routes:

  GET  /                           TumblingDiceWeb.PageController :home
  GET  /sets                       TumblingDiceWeb.SetLive.Index :index
  GET  /sets/new                   TumblingDiceWeb.SetLive.Index :new
  GET  /sets/:id/edit              TumblingDiceWeb.SetLive.Index :edit
  GET  /sets/:id                   TumblingDiceWeb.SetLive.Show :show
  GET  /sets/:id/show/edit         TumblingDiceWeb.SetLive.Show :edit
  GET  /dev/dashboard              Phoenix.LiveDashboard.PageLive :home
  GET  /dev/dashboard/:page        Phoenix.LiveDashboard.PageLive :page
  GET  /dev/dashboard/:node/:page  Phoenix.LiveDashboard.PageLive :page
  *    /dev/mailbox                Plug.Swoosh.MailboxPreview []

As I mentioned above, I just used mix phx.gen* to get the app set up and no custom code anywhere. And as I have no clue where to start, I'm not sure what additional source should be in this question.

I am looking for a solution but simply having a solid list of things I should be checking would be really helpful as well.

Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
jaydel
  • 14,389
  • 14
  • 62
  • 98
  • We would not be able to tell anything without seeing the code of the modal dialog itself. – Aleksei Matiushkin Jun 04 '23 at 02:28
  • I'll look for it. This is my first LiveView attempt so I'm not sure (yet) where it even is. – jaydel Jun 05 '23 at 12:15
  • You're looking for the heex template that contains the `
    ` or `<.form>` tag. Without a `phx-submit` attribute on it, it will attempt to do a POST by default. You need to add the attribute and a corresponding event in your liveview to handle the form submission.
    – doughsay Jun 06 '23 at 17:23
  • Okay, thanks. I'm kinda surprised that it doesn't just work "out of the box". I used the phx generators but nothing else. – jaydel Jun 10 '23 at 16:53

0 Answers0