Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the errors when incrementing the counter value #1003

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions exercises/phoenix_follow_along_counter_app.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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
belgoros marked this conversation as resolved.
Show resolved Hide resolved
number_as_string
|> String.trim()
|> String.to_integer()
end

def to_number(number) do
number
end
end
```

Expand Down Expand Up @@ -198,7 +208,7 @@ Add the link to the template in `counter_web/controllers/counter_html/count.html
<h1 class="text-4xl">The current count is: <%= @count %></h1>

<.link
navigate={~p"/?count=#{@count + 1}"}
navigate={~p"/?count=#{to_number(@count) + 1}"}
belgoros marked this conversation as resolved.
Show resolved Hide resolved
class="bg-cyan-500 hover:bg-cyan-400 text-2xl p-4 mt-4 rounded-full inline-block"
>
Increment
Expand Down