Ruby on rails Cocoon:更新时如何隐藏特定列

Ruby on rails Cocoon:更新时如何隐藏特定列,ruby-on-rails,ruby,cocoon-gem,Ruby On Rails,Ruby,Cocoon Gem,我正在开发一个像SNS这样的新应用程序。我用Cocoon堆叠案例用户更新组成员。UserGroup模型包括当前用户,但不应编辑当前用户,因此我不希望在用户编辑组成员时显示当前用户 我想跳过包含当前用户的列 apps/views/group/edit.html.erb <div class="formItem"> <h3>Group</h3> <%= f.fields_for :user_products do |m| %>

我正在开发一个像SNS这样的新应用程序。我用Cocoon堆叠案例用户更新组成员。UserGroup模型包括当前用户,但不应编辑当前用户,因此我不希望在用户编辑组成员时显示当前用户

我想跳过包含当前用户的列

apps/views/group/edit.html.erb

  <div class="formItem">
    <h3>Group</h3>
    <%= f.fields_for :user_products do |m| %>
      <div id="links">
        <%= render 'maker', f: m %>
      </div>
    <% end %>
    <%= link_to_add_association "Add member", f, :user_products, partial: 'maker' %>
  </div>

团体
apps/views/groups/_member.html.erb

<div class="nested-fields">
  <div class="formField">
    <%= f.collection_select :user_id, @cofounder, :id, :username, {}, class: "founderSelect" %>
    <%= link_to_remove_association "Remove member", f %>
  </div>
</div>

如果我理解正确,您想从联合创始人选择组中删除当前用户,对吗

您可以使用
@cofounder.where.not(id:current\u user.id)


我知道了。

你能用更好更清晰的英语更新吗?我还是没有得到你想要的do@buncis对不起,我的英语很差,我已经更新了我的问题。你能理解吗?你能解释得更清楚些吗?您不显示任何类/模型,但您的关系称为
user\u products
,表示用户和产品之间的关系。也不确定这是否是表单的父类,但您的注释似乎表明了某种项目,其中必须选择创始人?但是“用户”永远不能在项目中删除/编辑自己?这看起来很奇怪(尽管很容易实现)。你能更详细地解释一下你想要实现什么吗?@nathanvda非常感谢!我最终能做到。对不起,我解释得不好……这似乎是对OP问题的一个非常合理的解释。很好的解译:P:P非常感谢。根据你的建议,我可以做到这一点。
    <%= f.fields_for :user_products, f.object.user_products.where.not(user_id: current_user) do |m| %>
      <div id="links">
        <%= render 'maker', f: m %>
      </div>
    <% end %>