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

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement