在我的erb中我有:
<td>
<%= user_field.label :user_password_changed, "Do you wish to change your password?" %>
<%= user_field.check_box(:user_password_changed) %>
</td>
与此字段相关,我有Jquery可以正常工作:
$("input[type=checkbox]").on('change', function () {
var getid = this.id;
if (getid.includes('user_password_changed')) {
if (this.checked == true) { $("div#change_password").css("display", "block"); }
else { $("div#change_password").css("display", "none");}
} });
在相关模型中,User,user_password_changed不是字段。所以我使用attr_accessor,我在那里:
attr_accessor :user_password_changed
当我发布params时:
"user"=>{"role_id"=>"1", "user_changed"=>"1", "user_id"=>"50", "community_name"=>"foo", "username"=>"foo", "user_alias"=>"foo", "user_password_changed"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"foo", "user_type"=>foo}...