mismatch template
- Dominant language
- Elixir
- Stars
- 878
- Forks
- 44
- PR merge metrics
- No merged PRs in 30d
Description
I have a `login_controller` that renders `index.html.drab` in `templates/login/` with this content:
```
<%= if @error !== nil do %>
<%= @error %>
<% end %>
Login
```
I also defined the corresponding `login_commander` with simply:
```
defhandler login(socket, _sender) do
poke socket, error: "Test error!"
end
```
When clicking the button, i got this error
```
[error] Drab Handler failed with the following exception:
** (Phoenix.Template.UndefinedError) Could not render "lib/tgshop_web/templates/layout/app.html" for TgshopWeb.LoginView, please define a matching clause for render/2 or define a template at "lib/tgshop_web/templates/login/*". The following templates were compiled:
* index.html
Assigns:
%{conn: %Plug.Conn{adapter: {Plug.MissingAdapter, :...}, assigns: %{}, before_send: [], body_params: %Plug.Conn.Unfetched{aspect: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: "www.example.com", method: "GET", owner: nil, params: %Plug.Conn.Unfetched{aspect: :params}, path_info: [], path_params: %{}, port: 0, private: %{phoenix_action: :index, phoenix_controller: TgshopWeb.LoginController, phoenix_endpoint: TgshopWeb.Endpoint}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: "", remote_ip: nil, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: [], request_path: "", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}], scheme: :http, script_name: [], secret_key_base: nil, state: :unset, status: nil}, error: "Test error!", view_module: TgshopWeb.LoginView, view_template: "lib/tgshop_web/templates/layout/app.html"}
Assigned keys: [:conn, :error, :view_module, :view_template]
(phoenix 1.4.13) lib/phoenix/template.ex:341: Phoenix.Template.raise_template_not_found/3
(phoenix 1.4.13) lib/phoenix/view.ex:410: Phoenix.View.render_to_iodata/3
(phoenix 1.4.13) lib/phoenix/view.ex:417: Phoenix.View.render_to_string/3
(drab 0.10.3) lib/drab/live.ex:692: Drab.Live.rerender_template/4
(drab 0.10.3) lib/drab/live.ex:647: Drab.Live.process_poke/9
(drab 0.10.3) lib/drab.ex:360: anonymous fn/7 in Drab.handle_event/6
```
What did I do wrong? Do I have to use `mix drab.gen.commander Login` instead of creating the files by hand?
Contributor guide
Research direction
Start with lib/drab/live.ex around rerender_template/4 and compare the reported Phoenix.Template.UndefinedError with the templates in templates/login/ and layout/app.html. Reproduce the login button click using the shown commander and template. Done means the handler updates the error assign without a template-rendering failure and the expected error text is displayed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100