osindero

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

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
script
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
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
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
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
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

Latest on Elixir Forum

We're in Beta

About us Mission Statement