Skip to Main Content
Programming Phoenix
book

Programming Phoenix

by Chris McCord, Bruce Tate, Jose Valim
April 2016
Beginner to intermediate content levelBeginner to intermediate
300 pages
6h 58m
English
Pragmatic Bookshelf
Content preview from Programming Phoenix

Building Forms

Now that we have a database-backed repository, let’s add the ability to create new users in our system. We’re going to use Phoenix’s form builders for that purpose. First, open up your controller at web/controllers/user_controller.ex and set up a new user record for our new template, like this:

 alias Rumbl.User
 
 def​ new(conn, _params) ​do
  changeset = User.changeset(%User{})
  render conn, ​"​​new.html"​, ​changeset:​ changeset
 end

Notice the User.changeset function. This function receives a struct and the controller parameter, and returns an Ecto.Changeset. Changesets let Ecto manage record changes, cast parameters, and perform validations. We use a changeset ...

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

Programming Elm

Programming Elm

Jeremy Fairbank
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781680501926Errata Page