【问题标题】:Ruby On Rails 4 checkbox returned as filteredRuby On Rails 4 复选框作为过滤返回
【发布时间】:2017-11-16 20:35:37
【问题描述】:

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

当我发布参数时:

"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}... 

【问题讨论】:

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


    【解决方案1】:

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

    您可以像这样自定义它:How to filter parameters in rails?

    【讨论】:

    • 谢谢。我在这里看到了多个选项。我想在控制器内构建,或者我应该使用模型。哪个最好?
    • 误报...我仍然可以在控制器中询问参数:user_password_changed。一切顺利
    猜你喜欢
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多