Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何正确使用带ERB的bootstrap 3表?_Html_Ruby On Rails_Twitter Bootstrap 3 - Fatal编程技术网

Html 如何正确使用带ERB的bootstrap 3表?

Html 如何正确使用带ERB的bootstrap 3表?,html,ruby-on-rails,twitter-bootstrap-3,Html,Ruby On Rails,Twitter Bootstrap 3,“我有一个组织视图,我想在其中渲染一部分,以便向组织的用户显示一系列附加功能。为此,我设置了一个引导面板,在该面板中,我希望呈现一个引导表,以便显示属于该组织的每个用户。我可以让它在没有表css的情况下正常工作(就像单独的div元素每行显示一个用户一样),但是出于某种原因,当我创建一个表时,它会为每个用户对象构建全新的表(包括thead部分)。你能帮忙吗 组织显示页面html: <div class="col-md-6"> <ul class="users">

“我有一个组织视图,我想在其中渲染一部分,以便向组织的用户显示一系列附加功能。为此,我设置了一个引导面板,在该面板中,我希望呈现一个引导表,以便显示属于该组织的每个用户。我可以让它在没有表css的情况下正常工作(就像单独的div元素每行显示一个用户一样),但是出于某种原因,当我创建一个表时,它会为每个用户对象构建全新的表(包括thead部分)。你能帮忙吗

组织显示页面html:

<div class="col-md-6">
    <ul class="users">
    <div class="panel panel-default">
      <div class="panel-heading float-left">
        <% if current_user.admin? %>
        <%= link_to "Add more users", add_user_path(current_user.organization), class: "btn btn-large btn-success btn-panel" %>
        <% end %>
        <h2 class="panel-title">Users:</h2>
      </div>
        <div class="panel-body panel-height">
            <%= render partial: "users_index", collection: @users_index, as: :user %>
            <br></br>
        </div>
    </div>
    </ul>
</div>

我做错了什么?

在您的组织显示页面中,将表代码放在渲染线周围

    <div class="panel-body panel-height">
      <table class="table table-striped table-responsive">
       <thead>
        <tr>
          <th>Name</th>
          <th>Action</th>
        </tr>
       </thead>
       <tbody>
           <%= render partial: "users_index", collection: @users_index, as: :user %>
       </tbody>
      </table>
        <br></br>
    </div>

名称
行动


而你的实践将是

<tr>
    <td>
    <%= link_to user.name, user %>
    </td>
    <td>
    <% if current_user.admin? && !current_user?(user) %>
        <%= link_to "delete", user, method: :delete,
                                    data: {confirm: "You sure?" }, 
                                    class: "btn btn-sm btn-danger pull-right"%>
    <% end %>
    </td>
</tr>

看,在呈现集合时,Rails会查找与集合中的每个项匹配的部分,并为集合中的每个项呈现该部分,这就是为什么会为每个用户获得一个表,您需要的只是表中每个用户的一行,因此该部分只包含表行代码

    <div class="panel-body panel-height">
      <table class="table table-striped table-responsive">
       <thead>
        <tr>
          <th>Name</th>
          <th>Action</th>
        </tr>
       </thead>
       <tbody>
           <%= render partial: "users_index", collection: @users_index, as: :user %>
       </tbody>
      </table>
        <br></br>
    </div>
<tr>
    <td>
    <%= link_to user.name, user %>
    </td>
    <td>
    <% if current_user.admin? && !current_user?(user) %>
        <%= link_to "delete", user, method: :delete,
                                    data: {confirm: "You sure?" }, 
                                    class: "btn btn-sm btn-danger pull-right"%>
    <% end %>
    </td>
</tr>