2013-10-29 60 views
0

我有以下HAML代碼如何通過複選框的多個值在軌

%nav.breadcrumbs 
    %h2 Breadcrumbs 
    %ol 
    %li 
     %a{href: data_sources_path} #{t('Defaults.Home')} 
    %li 
     %a 
    %li 
     %em #{t('Registrations.new.AccessRequest')} 
%br 
%h3#content-header1.content-header #{t('Registrations.new.Header')} 
%section.form 
    %form.standard{action: registrations_path, method: 'post'} 
    %fieldset{"aria-labelledby" => "content-header"} 
     %input{type: 'hidden', name: 'authenticity_token', value: form_authenticity_token.to_s} 
     %legend 
     %ul 
     %li  
      %label 
      #{t('Registrations.new.CheckBoxHeader')} 
      %abbr.required{title: "Required"} * 
     - Role::ROLES.each do |role| 
      %input#roles{name: "access", type: "checkbox",value:"#{role}"}/ 
      %label{for: "roles"} #{role}    
    %fieldset.input-actions 
     %legend Actions 
     %input.primary-action{name: "invoke", type: "submit", value: t('Buttons.Send')}/ 
     %input.cancel{name: "invoke", type: "submit", value: t('Buttons.Cancel')}/ 

這裏想我的角色是管理和編輯......我可以成功地顯示角色的複選框,也PARAMS [:訪問]給了我我選擇的特殊角色。假設我選擇了兩個角色params [:access]只是返回admin。我想獲得這兩個角色。任何幫助,將不勝感激。由於

回答

0

你需要做一個簡單的技巧,使導軌看到「訪問」作爲一個數組

%input#roles{name: "access[]", type: "checkbox",value:"#{role}"}/ 

PARAMS這樣[:訪問]將是一個陣列上,你也可以遍歷

相關問題