Skip to content

Commit

Permalink
Step 11.2 Update / (default route) to invoke ItemController #36
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed May 29, 2020
1 parent 4ff844d commit 82f9070
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1867,16 +1867,65 @@ is to have a `?` (question mark) in the name of functions
that return a `true/false` result.

At the end of this step our `<footer>` element
is now hidden when there are no items.
is hidden when there are no items:

![phx-todo-footer-hidden](https://user-images.githubusercontent.com/194400/83268893-2bdd4100-a1be-11ea-88ac-f99f7e6efeda.gif)

<br />

### 11.2 Route `/` to `ItemController.index/2`

The final piece of tidying up we can do is
to change the Controller that gets invoked for the "homepage" (`/`)
of our app.
Currently when the person viewing the Todo App
visits [`http://localhost:4000/`](http://localhost:4000)
they see the `lib/app_web/templates/page/index.html.eex` template:

![page_template](https://user-images.githubusercontent.com/194400/83269042-6941ce80-a1be-11ea-80fa-73674576e928.png)

This is the default Phoenix home page
(_minus the CSS Styles and images that we removed in step 3.4 above_).
It does not tell us anything about the actual app we have built,
it doesn't even have a _link_ to the Todo App!
Let's fix it!

Open the `lib/app_web/router.ex` file and locate the line:
```elixir
get "/", PageController, :index
```

Update the controller to: `ItemController` e.g:

```elixir
get "/", ItemController, :index
```

e.g:
[]

Now when you run your App you will see the todo list on the home page:

![todo-app-on-homepage](https://user-images.githubusercontent.com/194400/83270006-cbe79a00-a1bf-11ea-8972-91097fdabdc1.png)

### 11.2 Route `/` to `ItemController.index/2`



Given that we are no longer _using_ the `Page`
Controller, View, Template or Tests,
we might as well **`delete`** them from our project!

```sh
git rm lib/app_web/controllers/page_controller.ex
git rm lib/app_web/templates/page/index.html.eex
git rm lib/app_web/views/page_view.ex
git rm test/app_web/controllers/page_controller_test.exs
```

Deleting files is good hygiene in any software project.
Don't be _afraid_ to do it, you can always recover files
that are in your `git` history.


### Deploy!

Expand Down
2 changes: 1 addition & 1 deletion lib/app_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule AppWeb.Router do
scope "/", AppWeb do
pipe_through :browser

get "/", PageController, :index
get "/", ItemController, :index
resources "/items", ItemController
get "/items/toggle/:id", ItemController, :toggle
get "/clear", ItemController, :clear_completed
Expand Down

0 comments on commit 82f9070

Please sign in to comment.