Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Creating our create function

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content