ruby-on-rails – Ruby on Rails 4选择多个

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Ruby on Rails 4选择多个前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个创建新用户的表单.我正在尝试添加一个下拉选项来选择权限级别.我想要能够为每个用户选择多个权限级别.

这是我的观点,我添加了{:multiple =>真:

<%= 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选择多个?

解决方法

class和multiple都是html_options的一部分,所以它们应该在一个哈希中一起进行.

更改

<%= f.select :permission,class: "input-lg" %>

<%= f.select :permission,{:multiple => true,class: "input-lg"} %>

现在你分别通过他们.所以select方法的参数计数为5,当它为4时.

原文链接:https://www.f2er.com/ruby/266715.html

猜你在找的Ruby相关文章