gpt4 book ai didi

ruby - 如果它是私有(private)方法,我该如何记录 URL 编码?

转载 作者:太空宇宙 更新时间:2023-11-03 17:47:24 24 4
gpt4 key购买 nike

使用 Ruby 1.9.1 或 1.9.3,我在将 % 符号插入数据库时​​遇到问题。

异常(exception)情况是:

/app/vendor/ruby-1.9.3/lib/ruby/1.9.1/uri/common.rb:898:in `decode_www_form_component' 

我被告知要使用p 来输出str

这是 ruby​​/lib/1.9.1/util/common.rb:

def self.decode_www_form_component(str, enc=Encoding::UTF_8)  

require 'logger'
# Keep data for the current month only
$LOG = Logger.new('this_month.log', 'monthly')
$LOG.debug("#{str.p}")

raise ArgumentError, "invalid %-encoding (#{str})" unless /\A[^%]*(?:%\h\h[^%]*)*\z/ =~ str
str.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
end

我遇到了这个错误:

Internal Server Error
cannot parse Cookie header: private method `p' called for "innate.sid":String

我如何p str 找出它里面的内容以及它可能是什么编码?

最佳答案

如果您使用记录器,则不需要 p 方法。 pputs 输出到标准输出。

# this is equavalent to `puts str`
$LOG.debug(str)

# for more "raw" data
# `p str` or `puts str.inspect`
$LOG.debug(str.inspect)

关于ruby - 如果它是私有(private)方法,我该如何记录 URL 编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33087148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com