首页 > 解决方案 > 为什么在 html 页面中有一个包含数据库记录的文本节点?

问题描述

所以在我的网站上,有一个不需要的文本节点,其中包含我的数据库记录。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 %>

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

标签: htmlruby-on-railsrubydatabase

解决方案


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

是问题,因为<%= %>ERB 代表“打印这个”。应该是<% %>哪个将执行 Ruby 代码而不渲染它。


推荐阅读