osindero
Issues with Importing Templates and Views from Phoenix 1.6 to new Phoenix 1.7
I am having errors with using my old views/layouts moved into a new Phoenix 1.7 application. Even though I have phoenix_view installed, it still trhows errors about templates not available. I desperately need help on how to handle this.
This is my router_web.ex include view and view_helpers
defmodule RationWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, components, channels, and so on.
This can be used in your application as:
use RationWeb, :controller
use RationWeb, :html
The definitions below will be executed for every controller,
component, etc, so keep them short and clean, focused
on imports, uses and aliases.
Do NOT define functions inside the quoted expressions
below. Instead, define additional modules and import
those modules here.
"""
def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)
def router do
quote do
use Phoenix.Router, helpers: true
# Import common connection and controller functions to use in pipelines
import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
end
end
def channel do
quote do
use Phoenix.Channel
end
end
def controller do
quote do
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: RationWeb.Layouts]
import Plug.Conn
import RationWeb.Gettext
unquote(verified_routes())
end
end
def view do
quote do
use Phoenix.View,
root: "lib/ration_web/templates",
namespace: RationWeb,
pattern: "**/*"
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
# Include shared imports and aliases for views
unquote(view_helpers())
end
end
defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View
import RationWeb.ErrorHelpers
import RationWeb.Gettext
alias RationWeb.Router.Helpers, as: Routes
end
end
def live_view do
quote do
use Phoenix.LiveView,
layout: {RationWeb.Layouts, :app}
unquote(html_helpers())
end
end
def live_component do
quote do
use Phoenix.LiveComponent
unquote(html_helpers())
end
end
def html do
quote do
use Phoenix.Component
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
# Include general helpers for rendering HTML
unquote(html_helpers())
end
end
defp html_helpers do
quote do
# HTML escaping functionality
import Phoenix.HTML
# Core UI components and translation
import RationWeb.CoreComponents
import RationWeb.Gettext
# Shortcut for generating JS commands
alias Phoenix.LiveView.JS
# Routes generation with the ~p sigil
unquote(verified_routes())
end
end
def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: RationWeb.Endpoint,
router: RationWeb.Router,
statics: RationWeb.static_paths()
end
end
@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
end
And a snippet of the controller with action throwing error
defmodule RationWeb.UserSessionController do
use RationWeb, :controller
alias RationWeb.UserAuth
alias RationWeb.WdApi
alias Ration.Utilities
alias Ration.Database
# alias Ration.Tenants
# # plug :put_layout, "landing.html"
# plug :put_layout, html: {RationWeb.Layouts, :root}
plug :put_layout, html: {RationWeb.UserSessionView, :landing}
def new(conn, params) do
host = conn.host
subdomain = get_subdomain(host)
license = Ration.Establishments.get_main_license()
titles = case license.edition do
"dc-on-premise" ->
Ration.Tenants.fetch_titles("")
_ ->
Ration.Tenants.fetch_titles(subdomain)
end
uidet = case license.edition do
"dc-on-premise" ->
Ration.Tenants.fetch_default_bg_image()
_ ->
Ration.Tenants.fetch_bg_image(subdomain)
end
logoimg = case license.edition do
"dc-on-premise" ->
Ration.Tenants.fetch_default_logo_image()
_ ->
Ration.Tenants.fetch_logo(subdomain)
end
layoutPage = case license.edition do
"dc-on-premise" ->
Ration.Tenants.fetch_default_layout()
_ ->
Ration.Tenants.fetch_layout(subdomain)
end
if layoutPage["layout"] == "juxtaposing" do
case Database.check_db(subdomain) do
{:ok, _db_name} ->
conn
|> assign(:tenant, subdomain)
|> render("new.html", error_message: params["error_message"], titles: titles, uidet_bgimg: uidet["img"], logo_img: logoimg["img"], layout: {RationWeb.LayoutView, "landing_two.html"}, content: layoutPage["content"])
_ ->
conn
|> assign(:tenant, subdomain)
|> render("new.html", error_message: params["error_message"], titles: titles, uidet_bgimg: uidet["img"], logo_img: logoimg["img"], layout: {RationWeb.LayoutView, "landing_two.html"}, content: layoutPage["content"])
end
else
case Database.check_db(subdomain) do
{:ok, _db_name} ->
conn
|> assign(:tenant, subdomain)
|> render("new.html", error_message: params["error_message"], titles: titles, uidet_bgimg: uidet["img"], logo_img: logoimg["img"], layout: {RationWeb.LayoutView, "landing.html"}, content: layoutPage["content"])
_ ->
conn
|> assign(:tenant, subdomain)
|> render("new.html", error_message: params["error_message"], titles: titles, uidet_bgimg: uidet["img"], logo_img: logoimg["img"], layout: {RationWeb.LayoutView, "landing.html"})
end
end
end
And the error
[debug] Processing with RationWeb.UserSessionController.new/2
Parameters: %{}
Pipelines: [:browser, :user, :redirect_if_user_is_authenticated]
[debug] Plug.Session could not verify incoming session cookie. This may happen when the session settings change or a stale cookie is sent.
[info] Sent 500 in 88ms
[error] #PID<0.650.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.647.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /users/log_in
** (exit) an exception was raised:
** (ArgumentError) no "new" html template defined for RationWeb.UserSessionHTML (the module does not exist)
(phoenix_template 1.0.3) lib/phoenix/template.ex:248: Phoenix.Template.render_with_fallback/4
(phoenix_template 1.0.3) lib/phoenix/template.ex:197: Phoenix.Template.render_within_layout/4
(phoenix 1.7.10) lib/phoenix/controller.ex:1000: anonymous fn/5 in Phoenix.Controller.template_render/4
(telemetry 1.2.1) /Users/osindero/dev/active/ration/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
(phoenix 1.7.10) lib/phoenix/controller.ex:987: Phoenix.Controller.render_with_layouts/4
(phoenix 1.7.10) lib/phoenix/controller.ex:974: Phoenix.Controller.render_and_send/4
(ration 0.1.0) lib/ration_web/controllers/user_session_controller.ex:1: RationWeb.UserSessionController.action/2
(ration 0.1.0) lib/ration_web/controllers/user_session_controller.ex:1: RationWeb.UserSessionController.phoenix_controller_pipeline/2
(phoenix 1.7.10) lib/phoenix/router.ex:432: Phoenix.Router.__call__/5
(ration 0.1.0) lib/ration_web/endpoint.ex:1: RationWeb.Endpoint.plug_builder_call/2
(ration 0.1.0) deps/plug/lib/plug/debugger.ex:136: RationWeb.Endpoint."call (overridable 3)"/2
(ration 0.1.0) lib/ration_web/endpoint.ex:1: RationWeb.Endpoint.call/2
(phoenix 1.7.10) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
(plug_cowboy 2.6.1) lib/plug/cowboy/handler.ex:11: Plug.Cowboy.Handler.init/2
(cowboy 2.10.0) /Users/osindero/dev/active/ration/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.10.0) /Users/osindero/dev/active/ration/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
(cowboy 2.10.0) /Users/osindero/dev/active/ration/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
(stdlib 3.17.2.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
And this is the error I am
Popular in Questions
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
I would like to know what is the best IDE for elixir development?
New
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Sometimes I want to check if the input into a function is not a blank string.
My first approach:
defmodule Example do
def do_stuff(s...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
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
Other popular topics
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
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
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
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
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







