简体   繁体   中英

collection_select from entities with specific attibute

Hi I have the following collection_select tag:

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

尝试这个

<%=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"})%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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