如果它是私有方法,我如何记录URL编码?

时间:2015-10-12 17:43:09

标签: ruby

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

例外是:

/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找出其中的内容以及可能的编码?

1 个答案:

答案 0 :(得分:4)

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

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

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