2013-10-22 56 views
0

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

%section.form 
    %form.standard{action: registration_index_path, method: 'get'} 
    %fieldset{"aria-labelledby" => "content-header"} 
     %legend 
     %ul 
     %li 
      %label{for: "Associate-id"} Associate Id 
      %input#Associate-id{name: "id", size: "80", type: "text", value: current_user.associate_username}/ 
     %li 
      %label{for: "email"} Email 
      %input#email{name: "email", size: "80", type: "text", value: current_user.display_name}/ 
     %li 
      %label{for: "reason"} Reason for Access 
      %textarea#reason{cols: "200", name: "description", value: ""} 
     %li 
      %label What type of access would you require? 
     - Role::ROLES.each do |role| 
      %input#roles{name: "access", type: "checkbox"}/ 
      %label{for: "roles"} #{role} 
    %fieldset.input-actions 
     %legend Actions 
     %input.primary-action{name: "invoke", type: "submit", value: "Send"}/ 
     %input.cancel{name: "invoke", type: "submit", value: "Cancel"}/ 

這裏PARAMS [:訪問]只給我,如果其對與否。我如何獲得所選複選框的值? 。 謝謝。

+0

這是在窗體的內部,一個rails框架窗體(form_for或form_tag)? – trh

+0

增加了整個haml只是爲了讓事情變得更容易。是的,它內部形式 –

回答

2

你需要使用value設定值,它會看起來更像是這樣的:

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

那麼對於的AdminVIPuserROLES列表,管理員的檢查框,則params [:訪問]將返回:

Admin 
+0

感謝噸阿米戈!!! ...像一個魅力工作:D –