wslでelixir その54

# 概要
wsl(wsl2じゃない)で、elixirやってみた。
練習問題、やってみた。

# 練習問題
Phoenixで、todoアプリを作れ。

# 方針

- phx.gen.html使う。
- コンテキストモジュール名　Todos
- スキーマモジュール名　Todo
- スキーマテーブル名　todos
- カラム名:型 title:string

# 手順

```
$ mix phx.gen.html Todos Todo todos title:string

* creating lib/hello2_web/controllers/todo_controller.ex
* creating lib/hello2_web/templates/todo/edit.html.heex
* creating lib/hello2_web/templates/todo/form.html.heex
* creating lib/hello2_web/templates/todo/index.html.heex
* creating lib/hello2_web/templates/todo/new.html.heex
* creating lib/hello2_web/templates/todo/show.html.heex
* creating lib/hello2_web/views/todo_view.ex
* creating test/hello2_web/controllers/todo_controller_test.exs
* creating lib/hello2/todos/todo.ex
* creating priv/repo/migrations/20230909214044_create_todos.exs
* creating lib/hello2/todos.ex
* injecting lib/hello2/todos.ex
* creating test/hello2/todos_test.exs
* injecting test/hello2/todos_test.exs
* creating test/support/fixtures/todos_fixtures.ex
* injecting test/support/fixtures/todos_fixtures.ex

Add the resource to your browser scope in lib/hello2_web/router.ex:

    resources "/todos", TodoController


Remember to update your repository by running migrations:

    $ mix ecto.migrate
```

- lib/hello2_web/router.ex修正

```
  scope "/", Hello2Web do
    pipe_through :browser

    get "/", PageController, :index
	resources "/todos", TodoController
  end
```

```

$ mix ecto.migrate
warning: the :gettext compiler is no longer required in your mix.exs.

Please find the following line in your mix.exs and remove the :gettext entry:

    compilers: [..., :gettext, ...] ++ Mix.compilers(),

  (gettext 0.23.1) lib/mix/tasks/compile.gettext.ex:5: Mix.Tasks.Compile.Gettext.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:36: Mix.Tasks.Compile.All.run/1

Compiling 5 files (.ex)
Generated hello2 app

06:43:15.362 [info]  == Running 20230909214044 Hello2.Repo.Migrations.CreateTodos.change/0 forward

06:43:15.371 [info]  create table todos

06:43:15.415 [info]  == Migrated 20230909214044 in 0.0s

```

- エンドポイント確認

```

$ mix phx.routes
warning: the :gettext compiler is no longer required in your mix.exs.

Please find the following line in your mix.exs and remove the :gettext entry:

    compilers: [..., :gettext, ...] ++ Mix.compilers(),

  (gettext 0.23.1) lib/mix/tasks/compile.gettext.ex:5: Mix.Tasks.Compile.Gettext.run/1
  (mix 1.13.4) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:92: Mix.Tasks.Compile.All.run_compiler/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:72: Mix.Tasks.Compile.All.compile/4
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:59: Mix.Tasks.Compile.All.with_logger_app/2
  (mix 1.13.4) lib/mix/tasks/compile.all.ex:36: Mix.Tasks.Compile.All.run/1

          page_path  GET     /                                      Hello2Web.PageController :index
          todo_path  GET     /todos                                 Hello2Web.TodoController :index
          todo_path  GET     /todos/:id/edit                        Hello2Web.TodoController :edit
          todo_path  GET     /todos/new                             Hello2Web.TodoController :new
          todo_path  GET     /todos/:id                             Hello2Web.TodoController :show
          todo_path  POST    /todos                                 Hello2Web.TodoController :create
          todo_path  PATCH   /todos/:id                             Hello2Web.TodoController :update
                     PUT     /todos/:id                             Hello2Web.TodoController :update
          todo_path  DELETE  /todos/:id                             Hello2Web.TodoController :delete
live_dashboard_path  GET     /dashboard                             Phoenix.LiveDashboard.PageLive :home
live_dashboard_path  GET     /dashboard/:page                       Phoenix.LiveDashboard.PageLive :page
live_dashboard_path  GET     /dashboard/:node/:page                 Phoenix.LiveDashboard.PageLive :page
                     *       /dev/mailbox                           Plug.Swoosh.MailboxPreview []
          websocket  WS      /live/websocket                        Phoenix.LiveView.Socket
           longpoll  GET     /live/longpoll                         Phoenix.LiveView.Socket
           longpoll  POST    /live/longpoll                         Phoenix.LiveView.Socket



```

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/9f539f78-55e7-1cd8-81b0-e34fed3d7424.png)


以上。