使用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
找出其中的内容以及可能的编码?
答案 0 :(得分:4)
如果您正在使用记录器,则不需要p
方法。 p
和puts
输出到stdout。
# this is equavalent to `puts str`
$LOG.debug(str)
# for more "raw" data
# `p str` or `puts str.inspect`
$LOG.debug(str.inspect)