0
votes

I am noticing that my cookies are not being set when I perform put_resp_cookie() before a redirect.

conn
|> put_resp_cookie("shop", shop)

if (some_condition) do:
  redirect conn, to: "/foo/bar"

In my controller function for /foo/bar, the cookie is not set. Is there a way to set the cookie?

1
Did you forget to reassign conn after setting the cookie? conn = conn |> put_resp_cookie(..)?Dogbert
I thought the syntax I used would do that, as per this blog post: amberbit.com/elixir-cocktails/phoenix/…sheldonkreger
Nope, a pipe doesn't reassign. The reason that code works is because it returns the new conn directly while you are doing an if after the pipe.Dogbert
@Dogbert Feel free to add an answer and I will accept it. That worked.sheldonkreger

1 Answers

1
votes

It appears you did not reassign conn. You simply piped conn into put_resp_cookie/2 but didn't capture the value. You probably intended to do something like this instead

conn = conn |> put_resp_cookie("shop", shop)