【问题标题】:Render table in partial Rails 4.0在部分 Rails 4.0 中渲染表格
【发布时间】:2014-06-01 21:13:50
【问题描述】:

有人可以帮我渲染部分表格视图吗?基本上,我有一个具有两个属性的链接模型:描述和 URL。我的链接模型是我的机会模型的嵌套资源。因此,当我在机会上单击“显示”时,我希望它显示机会然后显示属于该机会的所有链接。我希望将链接呈现到一个带有“描述”和“URL”列的表中。我当前的代码如下所示:

观点/机会:

<%= render @opportunity %>
<h3>Links</h3>
<div id = "links">
  <%= render @opportunity.links %>
</div>

视图/链接/_link

<%= div_for link do %>

    <p>Description:<%= link.description %></p>
    <p>URL: <%= link.link_url %></p>
    <span class='actions'>
            <%= link_to 'Delete', [@opportunity, link], :confirm => 'Are you sure?',
                :method => :delete %>
    </span>
<% end %>

【问题讨论】:

    标签: ruby-on-rails view partial


    【解决方案1】:

    你会想要...

    <%= render @opportunity %>
    <h3>Links</h3>
    <table id = "links">
      <thead><tr>
        <th>Description</th>
        <th>URL</th>
      </tr></thead>
    
      <tbody>
        <%= render @opportunity.links %>
      </tbody>
    </table>
    

    然后……

    <tr>
      <td><%= link.description %></td>
      <td><%= link.link_url %></td>
      <td><span class='actions'>
            <%= link_to 'Delete', [@opportunity, link], :confirm => 'Are you sure?',
                :method => :delete %>
      </span></td>
    </tr>
    

    我有点不清楚您是如何在部分中使用跨度的,因此我将其作为单独的列保留在表格中。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 2016-06-19
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多