我正在尝试在 rails 4 的表单中为单选按钮设置真/假值。我在 stackoverflow 上找到了一篇文章并相应地实现了我的单选按钮,但我总是将 false 作为值。
我的代码
<div><%= label :access_rights, 'Read Only', :value => "false" %></div>
<%= f.radio_button :access_rights, "Read Only", :checked => true , false%></div>
<div><%= label :access_rights, 'Read and Write', :value => "true" %></div>
<%= f.radio_button :access_rights, "Read and Write", true %>
是否有不同的方法来设置 rails 4 中的单选按钮的值?
编辑:
在我的控制器中
def access_params
params.require(:accessor).permit(:email, :access_rights)
end
参数:
{"utf8"=>"✓",
"authenticity_token"=>"t/da2RRBi4KsyndnHx4WNZLoOHu9DVlAWtl/59NPiMc=",
"accessor"=>{"accessor_id"=>"email",
"access_rights"=>"Read and Write"},
"commit"=>"Grant Permission"}