开发者

Rails avoid writing attribute of nested object to log

How can I prevent a certain parameter of a nested relationship in rails from entering the log file - I am writing LARGE files to a column in the db and don't want rails to write that to the log file.. I kn开发者_Go百科ow of filter_parameter_logging but it doesn't seem to work for nested models - I may just be putting in the wrong spot?


According to the Rails code this should work even for nested parameter hashes. You can implement the filter_parameters method on your controller to work around your issue. Read this thread for more details. I have posted the code from the thread above for your convenience.

  def filter_parameters(unfiltered)
    return unfiltered unless params[:action]  == 'payment'
    filtered = unfiltered.dup
    filtered[:creditcard] = unfiltered[:creditcard].dup
    filtered[:creditcard][:number] = '[FILTERED]'
    filtered[:creditcard][:type] = '[FILTERED]'
    filtered
  end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜