DockYard-Academy / curriculum

MIT License
947 stars 245 forks source link

Follow Along: Phoenix Counter App #988

Closed Pilot93 closed 1 year ago

Pilot93 commented 1 year ago

Describe the issue In "Increment the count" Cell there is a mistake.

This code doesn't work because of arithmetic error. navigate={~p"/?count=#{@count + 1}"}

Suggestion: navigate={~p"/?count=#{String.to_integer(@count) + 1}"}

After this in cell "Create The Controller increment/2 Action" we have to change code too

From: render(conn, :count, count: current_count + increment_by)

To: render(conn, :count, count: Integer.to_string(current_count + increment_by))

BrooklinJazz commented 1 year ago

This is already in the reading in the controller.

def increment(conn, params) do
  current_count = String.to_integer(params["count"])
  increment_by = String.to_integer(params["increment_by"])
  render(conn, :count, count: current_count + increment_by)
end

you can also refer to the demos/counter project.