简体   繁体   English

collection_select 从具有特定属性的实体中选择

[英]collection_select from entities with specific attibute

Hi I have the following collection_select tag:嗨,我有以下 collection_select 标签:

<%=collection_select(:post, :applicant_id, Room.all, :room_number, :room_number, {selected: @applicant.room_number}, { :onchange=>"window.location='#{room_select_path(@applicant.id)}?room_number=' + this.value"})%>

Currently, it displays all room entities available.目前,它显示所有可用的房间实体。

What I want to do is to display all room entities with the attribute :room_type.我想要做的是显示具有属性:room_type 的所有房间实体。

尝试这个

<%=collection_select(:post, :applicant_id, Room.where(room_type: "your_type_value"), :room_number, :room_number, {selected: @applicant.room_number}, { :onchange=>"window.location='#{room_select_path(@applicant.id)}?room_number=' + this.value"})%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM