Skip to content

Instantly share code, notes, and snippets.

@mazz
Last active Oct 22, 2020
Embed
What would you like to do?
runtime error
[error] an exception was raised:
** (Phoenix.Template.UndefinedError) Could not render "invitation_request.html" for ElijahWeb.InvitationRequestView, please define a matching clause for render/2 or define a template at "lib/elijah_web/templates/invitation_request/*". The following templates were compiled:
* invitation_request_loading.html
defmodule ElijahWeb.InvitationRequestController do
use ElijahWeb, :controller
alias Elijah.Accounts.Invitations
alias Elijah.Schema.InvitationRequest
def index(conn, _params) do
invitations = Invitations.list_invitations()
render(conn, "index.html", invitations: invitations)
end
def new(conn, _params) do
changeset = Invitations.change_invitation(%InvitationRequest{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"invitation" => invitation_params}) do
case Invitations.create_invitation(invitation_params) do
{:ok, invitation} ->
conn
|> put_flash(:info, "InvitationRequest created successfully.")
|> redirect(to: Routes.invitation_path(conn, :show, invitation))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
invitation = Invitations.get_invitation!(id)
render(conn, "show.html", invitation: invitation)
end
def edit(conn, %{"id" => id}) do
invitation = Invitations.get_invitation!(id)
changeset = Invitations.change_invitation(invitation)
render(conn, "edit.html", invitation: invitation, changeset: changeset)
end
def update(conn, %{"id" => id, "invitation" => invitation_params}) do
invitation = Invitations.get_invitation!(id)
case Invitations.update_invitation(invitation, invitation_params) do
{:ok, invitation} ->
conn
|> put_flash(:info, "InvitationRequest updated successfully.")
|> redirect(to: Routes.invitation_path(conn, :show, invitation))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", invitation: invitation, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
invitation = Invitations.get_invitation!(id)
{:ok, _invitation} = Invitations.delete_invitation(invitation)
conn
|> put_flash(:info, "InvitationRequest deleted successfully.")
|> redirect(to: Routes.invitation_path(conn, :index))
end
end
defmodule ElijahWeb.InvitationRequestListLive do
use Phoenix.LiveView
alias ElijahWeb.Router.Helpers, as: Routes
alias ElijahWeb.InvitationRequestListLive
alias Elijah.Repo
alias Elijah.Accounts.Invitations
alias Elijah.Schema.InvitationRequest
def mount(_params, %{"csrf_token" => csrf_token} = _session, socket) do
if connected?(socket), do: Phoenix.PubSub.subscribe(Elijah.PubSub, "app:#{csrf_token}")
assigns = [
conn: socket,
csrf_token: csrf_token
]
{:ok, assign(socket, assigns)}
end
def render(assigns) do
if connected?(assigns.conn) do
ElijahWeb.InvitationRequestView.render("invitation_request.html", assigns)
else
ElijahWeb.InvitationRequestView.render("invitation_request_loading.html", assigns)
end
end
def handle_event("nav", %{"page" => page}, socket) do
{:noreply, push_patch(socket, to: Routes.live_path(socket, InvitationRequestListLive, page: page))}
end
def handle_params(%{"page" => page}, _, socket) do
connected = connected?(socket)
assigns = get_and_assign_page(page, connected)
{:noreply, assign(socket, assigns)}
end
def handle_params(_, _, socket) do
connected = connected?(socket)
assigns = get_and_assign_page(nil, connected)
{:noreply, assign(socket, assigns)}
end
def handle_info({"paginate", %{"page" => page}}, socket) do
{:noreply, live_redirect(socket, to: Routes.live_path(socket, InvitationRequestListLive, page: page))}
end
def handle_info(_, socket), do: {:noreply, socket}
def get_and_assign_page(_page_number, false) do
total_count = Repo.aggregate(InvitationRequest, :count)
invitation_count = Enum.min([10, total_count])
[
invitation_requests: Enum.to_list(1..invitation_count)
]
end
def get_and_assign_page(page_number, _) do
%{
entries: entries,
page_number: page_number,
page_size: page_size,
total_entries: total_entries,
total_pages: total_pages
} = Invitations.paginate_invitations(page: page_number)
[
invitation_requests: entries,
page_number: page_number,
page_size: page_size,
total_entries: total_entries,
total_pages: total_pages
]
end
end
defmodule ElijahWeb.Router do
use ElijahWeb, :router
# , scope: "/admin", pipe_through: [:some_plug, :authenticate]
# use Kaffy.Routes
import ElijahWeb.UserAuth
import Plug.BasicAuth
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {ElijahWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug ElijahWeb.GenerateCSRF
plug ElijahWeb.AssignSession
plug :fetch_current_user
end
pipeline :api do
plug :accepts, ["json"]
end
pipeline :api_authenticated do
plug ElijahWeb.AuthAccessPipeline
end
pipeline :graphql do
plug ElijahWeb.Context
end
pipeline :admins_only do
plug :basic_auth, username: "admin", password: "secret"
end
scope "/admin" do
pipe_through [:browser, :admins_only]
end
scope "/rest", ElijahWeb.Api, as: :api do
pipe_through :api
post "/sign_in", SessionController, :create
scope "/search" do
post "/", SearchController, :searchv13
end
end
scope "/api" do
pipe_through :graphql
forward "/", Absinthe.Plug, schema: ElijahWeb.Schema
end
scope "/", ElijahWeb do
pipe_through :browser
live "/", PageLive, :index
end
# Enables LiveDashboard only for development
#
# If you want to use the LiveDashboard in production, you should put
# it behind authentication and allow only admins to access it.
# If your application does not have an admins-only section yet,
# you can use Plug.BasicAuth to set up some basic authentication
# as long as you are also using SSL (which you should anyway).
if Mix.env() in [:dev, :test] do
import Phoenix.LiveDashboard.Router
scope "/" do
pipe_through :browser
live_dashboard "/dashboard", metrics: ElijahWeb.Telemetry
end
end
## Authentication routes
scope "/", ElijahWeb do
pipe_through [:browser, :redirect_if_user_is_authenticated, :put_session_layout]
get "/users/register", UserRegistrationController, :new
post "/users/register", UserRegistrationController, :create
get "/users/redeem_invite/:token", UserRegistrationController, :redeem_invite
# show email entry login
get "/users/login", UserSessionController, :new
# user just POSTed email address, get matching User and send OTP/six-digit email
post "/users/login", UserSessionController, :create_otp
# post to this endpoint to receive otp token and show otp/six-digit form
# could not generate valid csrf_token -- DEPRECATED
post("/users/confirm_otp", UserSessionController, :confirm_otp)
# GET to this endpoint to receive otp token and show otp/six-digit form
get("/users/confirm_otp/:nonce", UserSessionController, :confirm_otp)
# POST to verify_otp to complete login verification process
post("/users/verify_otp", UserSessionController, :verify_otp)
end
scope "/", ElijahWeb do
pipe_through [:browser, :require_authenticated_user]
get "/users/settings", UserSettingsController, :edit
put "/users/settings/update_password", UserSettingsController, :update_password
put "/users/settings/update_email", UserSettingsController, :update_email
get "/users/settings/confirm_email/:token", UserSettingsController, :confirm_email
put "/users/settings/update_avatar", UserSettingsController, :update_avatar
put "/users/settings/update_phone_number", UserSettingsController, :update_phone_number
put "/users/settings/update_username", UserSettingsController, :update_username
put "/users/settings/update_name", UserSettingsController, :update_name
live "/invitations", InvitationRequestListLive # NEEDS TO BE ABOVE
resources "/invitations", InvitationRequestController
end
scope "/", ElijahWeb do
pipe_through [:browser]
delete "/users/logout", UserSessionController, :delete
get "/users/confirm", UserConfirmationController, :new
post "/users/confirm", UserConfirmationController, :create
get "/users/confirm/:token", UserConfirmationController, :confirm
end
if Mix.env() == :dev do
forward "/sent_emails", Bamboo.SentEmailViewerPlug
end
if Mix.env() == :dev do
forward "/graphiql", Absinthe.Plug.GraphiQL, schema: ElijahWeb.Schema
end
end
@mazz
Copy link
Author

mazz commented Oct 21, 2020

Screen_Shot_2020-10-21_at_7_00_59_PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment