2014-10-11 59 views
0

已经得到了一个组织视图,我想呈现一个局部视图,以便向组织的用户显示一堆附加功能。为此,我设置了一个Bootstrap面板,在此面板中,我想渲染一个引导表以显示属于组织的每个用户。我可以在没有表格CSS的情况下正常工作(就像单独的div元素每行显示一个用户一样),但由于某些原因,当我创建一个表格时,它会为每个用户构建全新的表格(包括thead部分)目的。你能帮我吗?如何正确使用带有ERB的引导程序3表?

组织显示页面的html:

<div class="table-responsive"> 
    <table class="table table-striped"> 
<thead> 
    <tr> 
    <th>Name</th> 
    <th>Action</th> 
    </tr> 
</thead> 
    <tbody> 
    <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> 
    </tbody> 
</table> 
</div> 

其中users_index定义的地方(我的组织控制显示功能):

def show 
@organization = Organization.find(params[:id]) 
@users_index = @organization.users 
end 

<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> 

我users_index部分的HTML

我在这里做错了什么?

回答

1

组织中的节目页面把表代码周围的渲染线

<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> 

而且你pratial会像

<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查找部分它为集合中的每个项目匹配并呈现它,这就是为什么您为每个用户获取表格的原因,您需要的仅仅是表格中的每个用户的一行,因此部分仅包含表格行代码。

相关问题