grych / grych/drab

(ArgumentError) assign @xxx not available in eex template.

Open
#181 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
878
Forks
44
PR merge metrics
No merged PRs in 30d

Description

I am currently getting this alert error in the browser when I click the input checkbox:

"An error occured. Please contact the System Administrator"

```
20:12:06.347 [error] Drab Handler failed with the following exception:
** (ArgumentError) assign @changeset not available in eex template.

Please make sure all proper assigns have been set. If this
is a child template, ensure assigns are given explicitly by
the parent template as they are not automatically forwarded.

Available assigns: [:action, :conn, :parent, :po_grantotal, :type, :view_module, :view_template]

(phoenix_html) lib/phoenix_html/engine.ex:116: Phoenix.HTML.Engine.fetch_assign/2

(epr) lib/epr_web/templates/payment_order/form.html.drab:1: EprWeb.PaymentOrderView."form.html"/1
(epr) lib/epr_web/templates/payment_order/new.html.drab:6: EprWeb.PaymentOrderView."new.html"/1
(phoenix) lib/phoenix/view.ex:332: Phoenix.View.render_to_iodata/3
(phoenix) lib/phoenix/view.ex:339: Phoenix.View.render_to_string/3
(drab) lib/drab/live.ex:674: Drab.Live.rerender_template/4
(drab) lib/drab/live.ex:629: Drab.Live.process_poke/9
(drab) lib/drab.ex:360: anonymous fn/7 in Drab.handle_event/6
```

**Mi current configuration:**

Drab 0.10.0
Phoenix 1.3.4
Phoenix_html 2.12.0 (currently locked due to fetch_assign/2 issue)

**This is the code:**

**The commander (payment_order_commander.ex):**
```
defmodule EprWeb.PaymentOrderCommander do
use Drab.Commander

defhandler invoice_selected(socket, _sender) do
poke socket, po_grantotal: 1000 * 1
end
end
```

**The controller (payment_order_controller.ex):**
```
defmodule EprWeb.PaymentOrderController do
........

def new(conn, _params, %Epr.Debts.Contract{} = document) do
invoices = Epr.Debts.list_unpaid_invoices(document)
changeset =
%PaymentOrder{}
|> Payments.new_payment_order()

render(
conn,
"new.html",
changeset: changeset,
parent: document,
invoices: invoices,
bank_accounts: Epr.Payments.list_all_bank_accounts(),
currency_us: document.currency_us,
po_grantotal: 0,
type: "contract"
)
end

end
```

**The main template (new.html.drab):**

This template is the one the controller renders. I tried using the eex extension instead of drab and experience the same error.

```

Nueva orden de pago

render "form.html", Map.put(assigns, :action, contract_payment_order_path(@conn, :create, @parent))
```

**The form (form.html.drab):**
```
<%= form_for @changeset, @action, fn f -> %>



<%= render "_invoices.html", conn: @conn, invoices: @invoices, parent: @parent %>

.......
<% end %>
```

**The first partial (_invoices.html.drab)**
```
...........

<%=
case @parent do
%Epr.Partners.Provider{} ->
for i <- @invoices do
render "_invoice_details.html", invoice: i, currency: i.currency_us
end

_ ->
for i <- @invoices do
render "_invoice_details.html", invoice: i, currency: @parent.currency_us
end
end
%>

.........
```

**The second partial (_invoice_details.html.drab):**

This partial has the input checkbox and drab-change event handeler.

```







<%= @invoice.proforma_invoice_number %>
<%= @invoice.exempt_order_number %>
<%= @invoice.invoice_number %>
<%= @invoice.date %>

........
```

Thanks in advance for the help.

Best regards.

Contributor guide

Open the contributing guide

Research direction

Reproduce the checkbox interaction and trace the failure from lib/drab/live.ex through the payment_order templates, especially form.html.drab and new.html.drab. Compare the assigns passed into the partials with the missing @changeset reported by phoenix_html; done means the interaction rerenders without the missing-assign ArgumentError.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.