Ruby On Rails 4复选框返回为已过滤

时间:2017-06-14 15:33:44

标签: ruby-on-rails-4 checkbox attr-accessor

在我的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}... 

1 个答案:

答案 0 :(得分:0)

仅在日志中过滤。这是出于安全考虑。

您可以自定义它,如下所示:How to filter parameters in rails?