【问题标题】:Why is there a text node that contains the database record inside the html page?为什么在 html 页面中有一个包含数据库记录的文本节点?
【发布时间】:2020-09-17 22:26:39
【问题描述】:

所以在我的网站上,有一个不需要的文本节点,其中包含我的数据库记录。 html代码上没有任何标签或元素,但不知何故它存在。

我估计是这行代码造成的:

<%= @workspace.items.each do |item| %>

<tr>
    <td><%= item.name %></td>
    <td><%= item.owner %></td>
    <td><%= item.quantity %></td>
    <td><%= item.details %></td>

    <td><%= link_to 'Edit Item', edit_workspace_item_path(@workspace,item) %></td>

    <td><%= link_to 'Delete', [item.workspace, item],
            method: :delete,
            data: { confirm: 'Are you sure?' } %></td>
</tr>

view.html.erb:

<p>
    <strong>Name:</strong>
    <%= @workspace.name %>
</p>
<p>
    <strong>maxitem:</strong>
    <%= @workspace.max %>
</p>
<p>
    <strong>details:</strong>
    <%= @workspace.details %>
</p>
<p>
    <%= link_to 'Edit Phase', edit_workspace_path(@workspace) %>
</p>
<p><strong>Items</strong>
</p>
<p>
    <%= link_to 'Add Item', new_workspace_item_path(@workspace) %></br>
</p>
<table>
    <tr>
    <tr>
        <th><strong>Name</strong>
        <th><strong>Owner</strong>
        <th><strong>Quantity</strong>
        <th><strong>Details</strong>
    </tr>
    <%= render 'items/item' %>
</table>
<%= link_to 'Back to List of Phases', workspaces_path %>

我不知道为什么这突然出现在我的网站上 like this

【问题讨论】:

    标签: html ruby-on-rails ruby database


    【解决方案1】:
    <%= @workspace.items.each do |item| %>
    

    是 ERB 中的 &lt;%= %&gt; 代表“打印此”的问题。应该是 &lt;% %&gt;,它将执行 Ruby 代码而不渲染它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      相关资源
      最近更新 更多