如何在select_tag中显示特定值?

时间:2018-11-02 04:35:52

标签: ruby-on-rails

这是我要为特定值更改的选择标签:

<div class="select_field">
      <%= select_tag 
      "quote[service_id]",options_for_select(AvailableService.all.map { |u|   
       [u.service_type.titleize+" - "+ (u.service_name == "housekeeping" ? 
       "House cleaning" : u.service_name), u.id] }), { prompt: "Select   
       Service", required: true } %>
     </div>

1 个答案:

答案 0 :(得分:0)

您可以使用collection_select

    <%= collection_select :service_id, AvailableService.where(service_type:"cleaning"), 
                    :id, :service_name, {}, {prompt:"Select Service", required: true} %>