Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug eex template and @ variables?

I have this template

  <%= form_for @changeset, bid_path(@conn, :update, 1), [method: :put], fn f -> %>
    <% 
      require IEx
      IEx.pry
    %>
<%= if @changeset.action do %>
  <div class="alert alert-danger">
    <p>Oops, something went wrong! Please check the errors below.</p>
  </div>
<% end %>

How can I display @changeset in IEx console? When I'm trying to do this is blows an error:

pry(5)> @changeset
** (ArgumentError) cannot invoke @/1 outside module
    (elixir) lib/kernel.ex:3960: Kernel.assert_module_scope/3
    (elixir) expanding macro: Kernel.@/1
             web/templates/bid/edit.html.eex:5: (file)
like image 397
piotrze Avatar asked Sep 08 '16 08:09

piotrze


People also ask

How do I debug a text template in Visual Studio?

You can set breakpoints in text templates. To debug a design-time text template, save the text template file, and then choose Debug T4 Template on the shortcut menu of the file in Solution Explorer. To debug a run-time text template, simply debug the application to which it belongs.

How do I debug a T4 text template?

Debugging a T4 Text Template. You can set breakpoints in text templates. To debug a design-time text template, save the text template file, and then choose Debug T4 Template on the shortcut menu of the file in Solution Explorer. To debug a run-time text template, simply debug the application to which it belongs.

How to debug text templates with temporary filename errors?

When the error report refers to a temporary filename, the usual cause is a mismatched bracket in the code of the text template. You can set breakpoints in text templates and debug in the usual way. The following table lists the most common errors and their fixes. Failed to load base class ' {0}' from which Transformation class inherits.

How do I use variables in a template?

You use variables to simplify your template. Rather than repeating complicated expressions throughout your template, you define a variable that contains the complicated expression. Then, you use that variable as needed throughout your template. Resource Manager resolves variables before starting the deployment operations.


1 Answers

@ in eex templates in Phoenix is completely unrelated to @ in Elixir/iex. In eex templates in Phoenix, @foo is roughly equivalent to Access.fetch!(assigns, :foo), while in Elixir/iex, they're used to define module attributes. So, in order to access @changeset in iex, you can can do:

Access.fetch!(assigns, :changeset)

or just the following if you're okay with getting nil for non-existent keys:

assigns[:changeset]
like image 153
Dogbert Avatar answered Oct 21 '22 16:10

Dogbert