Ruby on Rails 4 select multiple

后端 未结 3 716
小蘑菇
小蘑菇 2020-12-16 20:47

I have a form that creates new users. I am trying to add a drop down option to select permission levels. I want to be able to select multiple permission levels per user.

3条回答
  •  醉酒成梦
    2020-12-16 21:32

    class and multiple are both part of html_options, so they should go together in a single hash.

    Change

    <%= f.select :permission, [ ["Read Only", "read"], ["IP Voice Telephony", "ip_voice"], ["IP Video Telephony", "ip_video_telephony"], ["Enterprise Gateways", "enterprise_gateways"], ["Consumer ATAs", "consumer_atas"], ["IP PBX", "ip_pbx"], ["Master of All", "all"] ], {prompt: "Select Permission Level"},
    {:multiple => true}, class: "input-lg" %>
    

    To

    <%= f.select :permission, [ ["Read Only", "read"], ["IP Voice Telephony", "ip_voice"], ["IP Video Telephony", "ip_video_telephony"], ["Enterprise Gateways", "enterprise_gateways"], ["Consumer ATAs", "consumer_atas"], ["IP PBX", "ip_pbx"], ["Master of All", "all"] ], {prompt: "Select Permission Level"},
    {:multiple => true, class: "input-lg"} %>
    

    Right now you are passing them separately. So, the argument count for select method is becoming 5 when it should be 4. Hence, the error.

提交回复
热议问题