Creating a new poll

We have a nice new (well, okay, it's not that nice, but it is functional at least) interface for displaying our polls, but if we always have to go into an IEx terminal to create new polls it probably won't pick up in usage very quickly! Instead, we need to provide the users of the site with a simple web interface that they can use to create their own polls on demand! We'll do something very simple for our interface:

We'll also need to create two new actions in our controller to dictate the flow of new data into our database: new and create. The job of the new action is to set up the starting point of data that our form is going to work with, and create will handle actually creating the data and send some result of posting the form back to the end user! We should end up with a flow that looks like this:

We'll need to understand a little more about how the data needs to be set up for each request as well; the simplest way for us to do that is to actually go in and start mocking all of the code up! We'll start at the router level since we can't do anything or verify our results if we don't have a way for our web browser to actually get to that point! Open up lib/vocial_web/router.ex and let's get to work! We'll need to add in routes for new and create, the former of which will be a GET request and the latter of which will be a POST request. We'll add the following two lines to our router file:

get "/polls/new", PollController, :new
post "/polls", PollController, :create
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset