Howdy folks ðŸ¤
Basically, what I want to do is this:
# page controller - controllers/page_controller.ex
defmodule MyApp.PageController do
# ...
def create_game(conn, _params) do
game_id = #generate_game_id
# send user to /game/:game_id here, passing in the game id I just generated
end
def home(conn, _params) do
render(conn, :home, layout: false, create_game)
end
end
# home view - /controllers/page_html/home.html.heex
<button phx-click"@create_game()">Create Game</button>
On my home page, I want users to click a "Create Game" button that will start a Game process via a module I created called GameManager (Game is a Genserver module I created, and GameManager is also a GenServer that starts child processes under a Dynamic Supervisor). That should give me back a game_id, and then I want to send the user to a different route: /game/:game_id.
What is the right way to do this in Phoenix/Elixir? I tested the pieces that spawn the Game Processes and all of that seems to be working. Now I just want to wire this functionality up to a button and I'm struggling to see the right way to do it.