JulienCorb
ErrorView.render/2 is undefined
I made a check_admin Plug to check if user’s is_admin is equal to true. If so the user can access the page otherwise he gets a 404 error.
check_admin.ex:
defmodule Gazette.CheckAdmin do
import Phoenix.Controller
import Plug.Conn
def init(opts), do: opts
def call(conn, _opts) do
current_user = Guardian.Plug.current_resource(conn)
if current_user.is_admin do
conn
else
conn
|> put_status(:not_found)
|> render(Gazette.ErrorView, "404.html")
|> halt
end
end
end
this does not work when a non-admin user tries to get to page he is not supposed to; Hence the check_admin.ex Plug tries to redirect this user to 404.html but when it get to the error view I get the following error:
function Gazette.ErrorView.render/2 is undefined (module Gazette.ErrorView is not available)
error_view.ex:
def render("404.html", _assigns) do
"Page not found"
end
any idea ?
Marked As Solved
outlog
vs [quote=“JulienCorb, post:3, topic:12418”]
defmodule GazetteWeb.ErrorView do
[/quote]
so probably you want to change the render function to:
|> render(GazetteWeb.ErrorView, "404.html")
Also Liked
grych
function Gazette.ErrorView.render/2 is undefined, indeed. You’ve defined GazetteWeb.ErrorView.render/2. Notice Web
JulienCorb
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









