简体   繁体   English

如何在paper_trail中更改对象视图

[英]How to change the object view in paper_trail

I have used paper_trail gem for auditing in the application i am developing. 我已使用paper_trail gem在正在开发的应用程序中进行审核。 I am able to manage most of its features and i was able to display the data in versions table to the user. 我能够管理其大多数功能,并且能够向用户显示版本表中的数据。 In doing so the data in object attribute of the versions table is some what unreadable. 这样做,versions表的object属性中的数据有些不可读。 How can i make it be readable? 我如何使其可读? Here is my sample output of the object attribute: version.object retrieves in the following format in a single cell: 这是我的对象属性的示例输出: version.object在单个单元格中以以下格式检索:

--- budget_year: '2014' name: bbb reference_number: j789789 requesting_unit: '798789' quarter: II source_of_fund: Government budget_type: Recurrent procurement_method: Open Bidding procurement_level: National estimated_cost: 4455.0 currency: '4545' purchase_request_id: start_at: 2014-07-30 end_at: 2014-07-31 created_at: 2014-07-24 08:29:38.000000000 Z updated_at: 2014-07-24 08:29:38.000000000 Z id: 1

You could use reify method to see your data like, 您可以使用reify方法查看数据,例如

   > i=Invoice.last.versions.last

   => <PaperTrail::Version id: 158, item_type: "Invoice", item_id: 115, event: "update", whodunnit: "3", object: "---\nid: 115\ncreated_at: 2015-02-05 06:43:17.278448..."> 
 :038 > i.object
   => "---\nid: 115\ncreated_at: 2015-02-05 06:43:17.278448000 Z\nupdated_at: 2015-02-05 06:43:17.278448000 Z\nentity_type: Site\nentity_id: 928\ninvoice_id: WS/14\nuser_id: \nperson_id: \nstatus: 0\nperson_email:\nentity_value:\naddress: ''\nprice: '666'\ndetails: '{\"domain\"=>\"\", \"package\"=>\"23\", \"site_id\"=>\"928\", \"user_id\"=>\"394\", \"years\"=>\"1\"}'\norder_id: '464'\nnorder_type: \nyear: 1\npayment_type: cash\naccount_type: \ncheque_name: ''\ncomment: \ntax: \ncomments: 'Customer made payment by cash with receipt Nos: 041 & 042.'\ncheque_number: \nchequenumber: ''\npayment_level: \ninvoice_type: \n"

  > i.reify
  => <Invoice id: 115, created_at: "2015-02-05 06:43:17", updated_at: "2015-02-05 06:43:17", entity_type: "Site", entity_id: 928, invoice_id: "WS/14-15/D-2119", user_id: nil, person_id: nil, status: 0, address: "Near So...", price: "4999", details: "{\"domain\"=>\"\", \"package\"=>\"23\", \"site_id\"=>\"928\", ...", order_id: "464", order_type: nil, year: 1, payment_type: "cash", account_type: nil, cheque_name: "", comment: nil, tax: nil,, cheque_number: nil, chequenumber: "", payment_level: nil, invoice_type: nil> 

or 要么

> PaperTrail.serializer.load(i.object)
=> {"id"=>115, "created_at"=>2015-02-05 06:43:17 UTC, "updated_at"=>2015-02-05 06:43:17 UTC, "entity_type"=>"Site", "entity_id"=>928, "invoice_id"=>"W", "user_id"=>nil, "person_id"=>nil, "status"=>0, "person_email"=>"rium@gmail.com", "entity_value"=>"u.com", "address"=>"li ", "price"=>"4999", "details"=>"{}", "orr_id"=>"655", "processed_by"=>"", "order_type"=>nil, "year"=>1, "payment_type"=>"cash", "account_type"=>nil, "cheque_name"=>"", "comment"=>nil, "tax"=>nil, "comments"=>"Customer made payment by cash with receipt Nos: 041 & 042.", "cheque_number"=>nil, "chequenumber"=>"", "payment_level"=>nil, "invoice_type"=>nil}

second way will give the form of hash . 第二种方法将给出hash的形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM