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[:access] は、オンかどうかのみを示します。選択したチェックボックスの値を実際に取得するにはどうすればよいですか? . ありがとうございました。

4

1 に答える 1

2

を使用して値を設定する必要がありvalue ます。次のようになります。

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

、、 、および Admin のチェックボックスのリストについてROLESは、params[:access] は以下を返します。AdminVIPuser

Admin
于 2013-10-22T20:15:32.650 に答える