-2

如何where在选项选择中使用条件?以下代码不起作用:

<%= options_from_collection_for_select(@group,:groupname, :groupname).where(User_id: @user.id)%>

有人可以帮忙吗?

4

1 回答 1

1

options_from_collection_for_select接受记录和选项的集合并返回一个 HTML 字符串。.where因此,当您调用字符串时,这当然不会起作用。

您需要在集合上调用它。

<%= options_from_collection_for_select(@group.where(User_id: @user.id), :groupname, :groupname) %>
于 2018-12-26T00:37:25.420 回答