From c48bcda88efe57a4c17e1c051388df10174e2710 Mon Sep 17 00:00:00 2001 From: belgoros Date: Wed, 12 Jul 2023 15:39:19 +0200 Subject: [PATCH 1/2] Fix the errors when incrementing the counter value - the name of the action in the CounterController should be :count instead of :home - when passing a value via query parameters, it fails to be updated because the type of the @counter is of type String - add the helper method to the CounterHTML component to convert the String to Integer --- exercises/phoenix_follow_along_counter_app.livemd | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/exercises/phoenix_follow_along_counter_app.livemd b/exercises/phoenix_follow_along_counter_app.livemd index eed8f96a0..fd5fc7946 100644 --- a/exercises/phoenix_follow_along_counter_app.livemd +++ b/exercises/phoenix_follow_along_counter_app.livemd @@ -104,7 +104,7 @@ In `lib/counter_web/router.ex` modify the existing scope with the following. We' scope "/", CounterWeb do pipe_through :browser - get "/", CounterController, :home + get "/", CounterController, :count end ``` @@ -139,6 +139,16 @@ defmodule CounterWeb.CounterHTML do use CounterWeb, :html embed_templates "counter_html/*" + + def to_number(number_as_string) when is_binary(number_as_string) do + number_as_string + |> String.trim() + |> String.to_integer() + end + + def to_number(number) do + number + end end ``` @@ -198,7 +208,7 @@ Add the link to the template in `counter_web/controllers/counter_html/count.html

The current count is: <%= @count %>

<.link - navigate={~p"/?count=#{@count + 1}"} + navigate={~p"/?count=#{to_number(@count) + 1}"} class="bg-cyan-500 hover:bg-cyan-400 text-2xl p-4 mt-4 rounded-full inline-block" > Increment From e74b95f34ddf2327690e6ea38914a2d7f61d80af Mon Sep 17 00:00:00 2001 From: belgoros Date: Sat, 15 Jul 2023 13:15:20 +0200 Subject: [PATCH 2/2] Fix code review remarks - remove to_number/1 (fixed in the controller, see demos/counter) - remove the call to to_number/1 in the count.html.heex template --- exercises/phoenix_follow_along_counter_app.livemd | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/exercises/phoenix_follow_along_counter_app.livemd b/exercises/phoenix_follow_along_counter_app.livemd index fd5fc7946..86ade5b12 100644 --- a/exercises/phoenix_follow_along_counter_app.livemd +++ b/exercises/phoenix_follow_along_counter_app.livemd @@ -139,16 +139,6 @@ defmodule CounterWeb.CounterHTML do use CounterWeb, :html embed_templates "counter_html/*" - - def to_number(number_as_string) when is_binary(number_as_string) do - number_as_string - |> String.trim() - |> String.to_integer() - end - - def to_number(number) do - number - end end ``` @@ -208,8 +198,8 @@ Add the link to the template in `counter_web/controllers/counter_html/count.html

The current count is: <%= @count %>

<.link - navigate={~p"/?count=#{to_number(@count) + 1}"} - class="bg-cyan-500 hover:bg-cyan-400 text-2xl p-4 mt-4 rounded-full inline-block" + navigate={~p"/?count=#{@count + 1}"} + class="inline-block p-4 mt-4 text-2xl rounded-full bg-cyan-500 hover:bg-cyan-400" > Increment