String comparison in Elixir

I’m trying to compare to bits of string in Elixir - if they’re equal then the if block fires or the else block should fire.

def show(conn, %{"id" => id}) do
    Logger.info id
    Logger.info "----------"
    Logger.info conn.assigns.current_user
    if conn.assigns.current_user == id do
        professional = Repo.get!(Professional, id)
        render(conn, "show.html", professional: professional)
    else
      conn
      |> put_flash(:error, "You must be logged in for that!")
      |> redirect(to: site_path(conn, :index))
      |> halt()
    end

In the above, Logger.info id and Logger.info conn.assigns.current_user both return the same thing, but the if block is never entered.

What am I doing wrong?

Try to call inspect on both of them, like Logger.info inspect(id).

Maybe one of them is an int and the other is a string.

If that is the case, by setting up the calls to inspect, the int one will show up like 42 and the string one will show up like "42".

2 Likes