Why getting get_session error when using put_session?

Why getting get_session error when using put_session? See this screenshot. I am modifying the conn in my job_view.ex file. Also, could I change the conn variable anywhere like(view, controller, model or more).?

It makes more sense to copy the full error text into your topic - as it is most of the pertinent information is missing from the image you linked to.

The only useful bit of information is

no function clause matching in Plug.Conn.get_session/1

I suspect that it fails here:

which suggests that the conn argument you pass isn’t actually a %Plug.Conn{} struct (though it would seem odd that it gets passed conn.private).

Though additional error information may give some more insight.

From the limited information on the screenshot I’m not necessarily convinced that the error originates from the code you show (again the relevant error information is missing) - given how IO works, position of errors relative to IO.puts output isn’t necessarily a reliable indicator of the actual location of where the error occurs.

Unrelated - put_session/3:

The key can be a string or an atom, where atoms are automatically converted to strings.

So "share_job_opening_description" as a key would be clearer than :share_job_opening_description (which is converted to the string anyway).

1 Like

I think, actually, it is a socket (full screenshot). So, I may conclude that conn is my socket. Inspect conn before any modification, following things I get


So, How can I modify the “share_job_opening_description”?

@ycv005 In the future please copy and paste the actual text instead of using screenshots. If we want to highlight important text it forces us to type it by hand.

You can’t modify the session from a live view right now. It’s probably possible in theory, since javascript is allowed to change cookies, but phoenix would have to create hooks for it.

1 Like

Thanks will keep in mind about the code snippet.
But I can use the assign

  def get_copy_link_url(conn, job_opening, host, user) do
    |> assign(share_job_opening_description: job_opening.name)

Getting Error- undefined function assign/2

Two things:

  1. the function is 3 arity not 2, conn |> assign(: share_job_opening_description, job_opening.name)
  2. the conn is immutable, you need to rebind it:
conn = assign(conn, :share_job_opening_description, job_opening.name)
1 Like

Used your code conn = assign(conn, :share_job_opening_description, job_opening.name) . Getting error- undefined function assign/3.

My impression was that we are dealing with a liveview socket

def get_copy_link_url(socket, job_opening, host, user) do
    |> assign(share_job_opening_description: job_opening.name)
  • For assign/2, assign/3 to work use Phoenix.LiveView is necessary

The bigger question is: to what end are you doing this? What greater objective are you trying to accomplish?

Because right now this feels like an XY Problem.

Please show the full module that this is in.