April 2018
Beginner to intermediate
406 pages
9h 33m
English
We have a new form that is sending data along to our create controller action, but nothing to actually handle that. We'll jump back into lib/vocial_web/controllers/poll_controller.ex and add a new create function and pattern match on the following:
def create(conn, %{"poll" => poll_params, "options" => options}) do split_options = String.split(options, ",") with {:ok, poll} <- Votes.create_poll_with_options(poll_params, split_options) do conn |> put_flash(:info, "Poll created successfully!") |> redirect(to: poll_path(conn, :index)) end end
We're expecting to see both a poll and an options parameter be passed in. We know that our options should be a comma joined list of poll options, as well. We're going to make ...