Skip to content

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

Description

@joaquinalcerro

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.

<p class="title1">Nueva orden de pago</p>

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 -> %>
  <div class="row">
    <div class="col-md-12">
      <%= render "_invoices.html", conn: @conn, invoices: @invoices, parent: @parent %>
    </div>
.......
<% end %>

The first partial (_invoices.html.drab)

...........
  <tbody>
  <%= 
    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
  %>
  </tbody>
</table>
.........

The second partial (_invoice_details.html.drab):

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

<tr name="invoice">
  <td>
        <span class="text-right">
          <input type="hidden" name="invoices[<%= @invoice.id %>][paid]" value="false"> 
          <input type="checkbox" id="<%= @invoice.id %>" name="invoices[<%= @invoice.id %>][paid]" value="true" drab-change="invoice_selected" checked> 
        </span>
  </td>
  <td><%= @invoice.proforma_invoice_number %></td>
  <td><%= @invoice.exempt_order_number %></td>
  <td><%= @invoice.invoice_number %></td>
  <td><%= @invoice.date %></td>
  <td class="<%= active_icon(@invoice.exempt) %>"></td>
........

Thanks in advance for the help.

Best regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions