Passing second parameter to render function in phoenix

 def render("login.json", %{jwt: jwt, user: user}) do
    %{data: render_one(%{jwt: jwt, user: user}, Catastore.SessionView, "session.json")}

  def render("session.json", %{jwt: jwt, user: user}) do
    IO.inspect jwt
      access_token: jwt,
      user: #user render many

but this give me error

Which one?

Only glancing, I’d guess that there will be a compile time warning about unused variable user, but can’t see and error (at least not compile time)…

i am sorry was a bit sleepy i copy the code wrong updated the question now

I’d prefered if you had answered just my question with updated code, now my last post is out of context…

Despite this, you didn’t tell us what error you get.

1 Like

I’m not seeing any error in your post?

However I’m guessing that the render_one call in your first render function is wrong, as I don’t think you have anything that accepts a map for the resource? ^.^;

oh sorry, was so sleepy and doing thing too fast xD here the error code :

Could not render “session.json” for Catastore.SessionView, please define a matching clause for render/2 or define a template at “web/templates/session”

here is my render code
render(conn, "login.json", %{jwt: jwt, user: user})

You probably want this as:

%{data: render(Catastore.SessionView, "session.json", %{jwt: jwt, user: user})}
1 Like

Thank you it work now but just out of curiosity why can i pass the map like that ?

Well in render_one it is expecting a single element that it will then put in a names assign (defaults to something that I don’t remember, can rename it with as: :blah).

The render function takes the set of assigns as it’s last argument.

1 Like

i see, thank you very much i got it now

1 Like