来自具有特定属性的实体的collection_select

时间:2016-05-07 08:10:38

标签: html ruby-on-rails ruby ruby-on-rails-4

您好我有以下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"})%>

目前,它显示所有可用的房间实体。

我想要做的是显示具有属性的所有房间实体:room_type。

1 个答案:

答案 0 :(得分:1)

试试这个

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