【问题标题】:formatting a list in rails在rails中格式化列表
【发布时间】:2016-03-07 06:27:21
【问题描述】:

我正在尝试格式化此列表,以便每个单独的部分(名称、饮食、运行 # 和所有者)分开并具有相同的边距。我想我必须在_patient.html.erb 中更改一些内容,但我不确定如何。

我现在的_patient.html.erb

<li>
  <%= link_to patient.name + " #{patient.owner.last_name} ", patient %>
  <%= link_to patient.diet, patient, style: "color:red;" %>
  <% if patient.stays.length > 0 %>
      <%= Runn.find_by_id(patient.stays.last.runn_id).ident %> 
  <% end %> 
  (Owned by <%= link_to "#{patient.owner.first_name} #{patient.owner.last_name}", patient.owner %>)
</li>

这是index.html.erb

<h1>Patients</h1>
<div>
    <%= link_to "Generate Feed List", new_feed_list_path, class: "btn btn-lg btn-primary"%>
</div>

<% provide(:title, 'All patients') %>
<%= will_paginate %>
<ul class="patients">
  <%= render @patients %>
</ul>
<%= will_paginate %>

【问题讨论】:

  • 你不使用桌子有什么原因吗?
  • 这是我的第一个 Rails 项目,所以我边走边学
  • 我现在看看表格
  • @Yang 表格如何让响应变得更加困难? OP 似乎正在使用 Bootstrap,其中包括 responsive tables。即使你没有使用 Bootstrap,it's quite easy to make a table responsive
  • @JoeKennedy 响应式表格的原理是在屏幕太小无法显示所有列时隐藏其中的一些。不能像使用&lt;div&gt;&lt;span&gt; 那样将它们向下移动。

标签: html css ruby-on-rails


【解决方案1】:

我建议使用HTML table,而不是列表。

index.html.erb 中,而不是&lt;ul&gt;

<table class='patients'>
  <tbody>
     <%= render @patients %>
  </tbody>
</table>

您的新_patient.html.erb 文件:

<tr>
  <td>
     <%= link_to patient.name + " #{patient.owner.last_name} ", patient %>
  </td>
  <td>
    <%= link_to patient.diet, patient, style: "color:red;" %>
  </td>
  <td>
    <% if patient.stays.length > 0 %>
      <%= Runn.find_by_id(patient.stays.last.runn_id).ident %> 
    <% end %>
  </td>
  <td>
    (Owned by <%= link_to "#{patient.owner.first_name} #{patient.owner.last_name}", patient.owner %>)
  </td>
</tr>

我还建议从我上面发布的链接中阅读更多关于表格的信息。

【讨论】:

    【解决方案2】:

    你是对的。我会建议你在&lt;li&gt; 中添加一个类,例如:

    <li class="patient-item">
    

    然后更改 margin 或您想要的 css 文件中的任何样式。

    【讨论】:

    • 我必须在我的 css 文件中添加什么?像这样的东西? patinet-item { #margin 东西在这里 }
    猜你喜欢
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    • 2011-05-20
    • 2016-12-19
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多