awesome_print看起来像一个非常好的宝石,所以我想尝试一下.
我去了我的一个项目并做了:
gem install awesome_print
Run Code Online (Sandbox Code Playgroud)
并说它安装了一个gem,安装了文档等.
然后,当我在那个项目中时,我去了我的Rails控制台尝试一下,但是当我require "awesome_print"
按照他们的帮助文件说的那样,我得到一个"无法加载这样的文件".
有人有这个工作吗?
我正在测试rails控制台中的active-model-serializer输出,我正在寻找一种美化输出的方法.到目前为止我找到的唯一解决方案是:
ap JSON.parse(ProfileSerializer.new(p).to_json)
Run Code Online (Sandbox Code Playgroud)
这似乎是一种迂回的方法.有没有更好的办法"?
ruby-on-rails rails-console active-model-serializers awesomeprint
如何让AwesomePrint.ap显示嵌套在对象中的关联对象?默认情况下它没有这样做,我假设有办法强迫它?
我有一个 webhooks 控制器,我希望能够以良好的可读格式查看打印到开发中的服务器日志的参数。Awesome_print 适合这个吗?我正在尝试使用 Prettyprint,例如下面的示例,但格式仍然不太可读。
尝试使用 PrettyPrint 来格式化参数
class DwollaWebhooksController < WebhooksController
require 'pp'
def create
pp params
case params[:topic]
when 'customer_funding_source_verified'
puts '----------customer_funding_source_verified-----------------'
end
end
Run Code Online (Sandbox Code Playgroud)
输出如下所示
<ActionController::Parameters {"id"=>"57dec892", "resourceId"=>"a0d172yx", "topic"=>"customer_bank_transfer_completed",...} permitted: false>
Run Code Online (Sandbox Code Playgroud)
我正在寻找至少有适当缩进、多行等的东西
如何让awesome_print成为heroku控制台的默认设置?
当我输入Model.all
控制台时,我希望awesome_print显示结果而不必输入ap Model.all
.
令人敬畏的打印通常在Rails中完美适用于我.
但是当ap Post.all
在Rails控制台中进行操作时,我只获得标准的全线输出.
它与返回的ActiveRecord_Relation
类或其他东西有关,因为当返回一个数组时,就像在ap Post.all.each {|p| p}
,Awesome Print这样做.
我试图awesome_print
输出到文件而不是控制台,但我不知道如何做到这一点?
require "awesome_print"
mySymbolizedHash = {'blah' => 'blabbbb', 'this' => 'that'}
Run Code Online (Sandbox Code Playgroud)
ap mySymbolizedHash
Run Code Online (Sandbox Code Playgroud) 我将awesome_print配置为我在IRB中的默认格式化程序(AwesomePrint.irb!
在我的.irbrc中使用)虽然这通常很棒,但我想有时将其关闭.有人知道如何从正在运行的IRB/Rails控制台?
我想在我的控制台中调用它(ap
是很棒的打印宝石):
ap Purchase.last(10)
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash
Run Code Online (Sandbox Code Playgroud)
它的工作原理如下:
irb(main):020:0> ap Purchase.last
#<Purchase:0x00007f86b792a320> {
:id => 28445,
:user_id => 10177,
:product_id => nil,
:product_type => nil,
:price => 9.0,
:gateway_code => nil,
:gateway_msg => nil,
:gateway_response => nil,
:created_at => Fri, 18 May 2018 22:20:10 UTC +00:00,
:updated_at => Fri, 18 May 2018 22:20:10 UTC +00:00,
:checkout_total => 9.0,
:successful => true,
:cart_id => 17242,
:report_errors => nil,
:transacted_value_of_products => 9.0,
:comp_credits_applied => 0.0 …
Run Code Online (Sandbox Code Playgroud) ruby-on-rails strong-parameters awesomeprint rails-activerecord
awesomeprint ×9
ruby ×3
file ×1
gem ×1
heroku ×1
irb ×1
output ×1
pretty-print ×1
printing ×1
rubygems ×1