茧:更新时如何隐藏特定的列

时间:2019-03-16 04:04:46

标签: 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| %>
      <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>

2 个答案:

答案 0 :(得分:1)

如果我理解正确,您想从共同创始人选择组中删除current_user吗?

您可以使用@cofounder.where.not(id: current_user.id)

答案 1 :(得分:0)

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

我明白了。