我有一個創建新用戶的表單。我正在嘗試添加一個下拉選項來選擇權限級別。我希望能夠爲每個用戶選擇多個權限級別。Ruby on Rails 4選擇多個
這是我的看法,我說{:multiple => true}
:
<%= f.label :permission, "Permission Level" %>
<%= 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" %>
我的控制,我加:permission => []
:
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation, :admin, :permission => [])
end
爲我的觀點錯誤,f.select:
wrong number of arguments (5 for 2..4)
你如何爲Rails 4選擇多個?
+1解釋,哇,你能不能請您給一個參考,我有一個很難找到一個。 – DDDD
您可以查看http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select和http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select –
那麼,我以爲我是第一個。刷新頁面。 :D –