Elixir Phoenix Flash消息不显示

标签 elixir phoenix-framework

我正在尝试在Phoenix应用程序中显示Flash消息,但它们似乎没有显示。我尝试了很多不同的东西,其中之一是:

<div class="row">
  <div class="col-sm-12">
    <%
    info = get_flash(@conn, :info)
    error = get_flash(@conn, :error)
    %>
    <% if info do %>
      <div class="alert alert-info" role="alert"><%= info %></div>
    <% end %>
    <% if error do %>
      <div class="alert alert-danger" role="alert"><%= error %></div>
    <% end %>
  </div>
</div>

谁能指出我正确的代码?

最佳答案

您需要使用<%=而不是<%

<%= if info do %>
  <div class="alert alert-info" role="alert"><%= info %></div>
<% end %>

the docs:

All expressions that output something to the template must use the equals sign (=). Since everything in Elixir is an expression, there are no exceptions for this rule. For example, while some template languages would special-case if clauses, they are treated the same in EEx and also require = in order to have their result printed:

关于Elixir Phoenix Flash消息不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34068589/

相关文章:

Elixir /Phoenix LiveView : How can I report exceptions to Rollbar?

erlang - 如何修复在 Windows 上编译 bcrypt_elixir 或 argon_elixir 的错误?

json - 为自引用 Ecto 模型构建 JSON 映射

reactjs - 图片未加载但路径正确

phoenix-framework - Phoenix 相当于 Rails.env.production?

elixir - 在 Phoenix/Ecto 中混合范围和关联

postgresql - 查询 View 和函数

elixir - Elixir 记录中括号语法的使用

postgresql - 无法使用对等身份验证在没有密码的情况下运行 `mix ecto.migrate`

database - 如何通过算法修改字段