【问题标题】:Content_tag_for malfunction in rails 3.2Rails 3.2 中的 Content_tag_for 故障
【发布时间】:2013-07-19 18:33:04
【问题描述】:

我有需要循环浏览的搜索结果。每个循环应该给我两个表格行。到目前为止的代码是:

<tbody>
  <%= content_tag_for(:tr, @results) do |material| %>
     <tr>
       <td>Some content</td>
       <td>Some content</td>
       <td>Some content</td>
     </tr>
     <tr class="hide">
       <td>Some content</td>
       <td>Some content</td>
       <td>Some content</td>
     </tr>
   <% end %>
 </tbody>

问题是我在单独的行中的两行上方获得了一个类和 id。我需要将这两行包装在带有 id 的 a 中。

例如

<tr class="X" id="X"></tr>
<tr>
  <td>Some content</td>
  <td>Some content</td>
  <td>Some content</td>
</tr>
<tr class="hide">
  <td>Some content</td>
  <td>Some content</td>
  <td>Some content</td>
</tr>

当我尝试使用 div_for 时,我也遇到了同样的问题。在这种情况下,我得到所有 id 的 div 都堆叠在行之前。

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 for-loop tags


    【解决方案1】:

    问题是你不能使用这种方法将 a 包装在另一个中。解决方案是编写以下内容:

    <tbody>
      <%= content_tag_for(:tr, @results) do |material| %>
        <td>Some content</td>
        <td>Some content</td>
        <td>Some content</td>
    
        <tr class="hide">
          <td>Some content</td>
          <td>Some content</td>
          <td>Some content</td>
        </tr>
     <% end %>
    </tbody>
    

    前三个用 id 包裹在 a 中,而另一个只是逐字复制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      相关资源
      最近更新 更多