Hizqeel

Hizqeel

Render Expects Template to be a String

Hi, I am writing an authentication plug, upon failure I am rendering to 403 error page

    case claims do
      {:ok, claims} ->
        conn
        |> put_status(200)

      _ ->
        conn
        |> render("forbidden.html")
        |> halt()
    end

It gives me this error

** (ArgumentError) render/2 expects template to be a string, got: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{}

I don’t know what I am doing wrong here, Any help would be highly appreciated!

Marked As Solved

Hizqeel

Hizqeel

As I was rendering the user to error page so what I did is create a render function in View and render template there:

  def render("403.html", _assigns) do
    render("forbidden.html", %{})
  end

and in my authentication pipe:

case claims do
  {:ok, claims} ->
    conn
    |> put_status(200)

   _ ->
    conn
    |> put_status(403)
    |> put_view(MyAppWeb.PageView)
    |> render("403.html")
    |> halt()
end

Also Liked

hauleth

hauleth

Are you sure you are using correct render/2 function? Especially as in this case you should use put_view/2 or render/3.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement