我有这个模板
<%= 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 %>
如何在 IEx 控制台中显示@changeset?当我尝试这样做时,会出现错误:
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)
@
in eex
Phoenix 中的模板与以下内容完全无关@
在 Elixir/iex 中。在eex
凤凰城的模板,@foo大致相当于Access.fetch!(assigns, :foo) https://github.com/phoenixframework/phoenix_html/blob/77da6b4dc99d6f5ec1acf71dc7601d0fd13b5e2b/lib/phoenix_html/engine.ex#L90-L113,而在 Elixir/iex 中,它们用于定义模块属性。所以,为了访问@changeset
in iex
,你可以这样做:
Access.fetch!(assigns, :changeset)
或者如果您愿意的话,只需执行以下操作nil
对于不存在的键:
assigns[:changeset]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)