Chapter 9. Transforming data in your browser

 

This chapter covers

  • Creating and editing items in the browser
  • Creating new Phoenix routes, controllers, views, and templates
  • Using Phoenix’s form-builder helpers to create HTML forms

You can create, edit, and delete auction items and persist the changes in a real database, but you currently have no way to use those functions in the browser. What you need are HTML forms that enable users of your site to do those things—you certainly aren’t giving them access to your IEx console.

In this chapter, you’ll create those forms. As you do so, you’ll touch almost every part of the route that data takes on its way through Phoenix—from the router to the template (we discussed that route in chapter 3).

Figure 9.1 shows how a user request travels through Phoenix. You can trace a user request through the server, endpoint, router, controller, view, and template, back to the user. With the exception of the endpoint, you’ll touch on each of these areas in this chapter.

Figure 9.1. A trace of a user request as it goes through Phoenix

9.1. Handling new routes in your application

You need a way for your users to get to the web page they’ll interact with—you need a route that will respond to a request for a URL. The router module for your application can be found at auction_umbrella/apps/auction_web/lib/auction_web/router.ex.

9.1.1. Adding a new route

9.2. Viewing the details of a single item

9.3. Creating items through web forms

9.4. Editing items through web forms

Summary