Ruby on rails 如何在rails中传递复选框的值
我有下面的haml代码Ruby on rails 如何在rails中传递复选框的值,ruby-on-rails,ruby-on-rails-3,haml,Ruby On Rails,Ruby On Rails 3,Haml,我有下面的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 %inpu
%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]仅在其是否打开时提供。如何实际获取所选复选框的值。
谢谢。您需要使用
value
设置值,它看起来更像这样:
%input#roles{name: "access", type: "checkbox", value:"#{role}"}/
然后,对于管理员
、VIP
、用户
的角色
列表以及管理员复选框,params[:access]将返回:
Admin
这是表单的内部吗?rails框架表单(form_for或form_tag)?添加整个haml只是为了让事情变得更简单。是的,它在一个表格里