所以我有一个表格:
<%= form_for @role, :html => {:class => 'form-horizontal'} do |f|%>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<h3>Create a new role</h3>
<p class="text-muted">Create a new role below.</p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6">
<%= render :partial => 'form_errors', :object => @user %>
</div>
</div>
<div class="form-group">
<%= f.label :role, :class => 'col-sm-2 control-label' %>
<div class="col-sm-6">
<%= f.text_field :role, :class => 'form-control' %>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label'">Select permissions for this role</label>
<div class="col-sm-6">
<%= f.select(:permissions, options_for_select(Xaaron::Permission.pluck(:permission),
:selected => @role.permissions), :class => 'form-control') %>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<%= f.submit "Create Role", :class => 'btn btn-primary' %>
</div>
</div>
<% end %>
您会注意到有一个允许您选择角色权限的选择框,我希望这是一个多选框,允许您为角色选择多个权限,并且还有css它目前没有的form-control
类。
答案 0 :(得分:0)
尝试
<div class="form-group">
<label class="col-sm-2 control-label'">Select permissions for this role</label>
<div class="col-sm-6">
<%= f.select(:permissions, options_for_select(Xaaron::Permission.pluck(:permission),
:selected => @role.permissions), {}, {:multiple => true, :class => 'form-control'}) %>
</div>
</div>