简体   繁体   English

如何在视图中使用 paper_trail 格式化变更集的输出?

[英]How do I format the output from changeset using paper_trail in a view?

# reports\workorder_version.html.haml
%table
%class='Work Orders'
  %tr
  %thead
    %tr
      %th Index
      %th Date
      %th User ID
      %th Event
      %th Item Type
      %th Item ID
      %th Change Set
      %th IP Address
    %tr

  %tbody
    - workorder = Workorder.where(:id => params[:id]).first
    - workorder.versions.reverse.each do |version|
      %tr
        %td= version.index
        %td= version.created_at.in_time_zone('Eastern Time (US & Canada)')
        %td= Employee.find(version.whodunnit.to_i).full_name.upcase
        %td= version.event.humanize
        %td= version.item_type.humanize
        %td= version.item_id
        %td= version.changeset.to_s.humanize
        %td= version.ip

My output:我的输出:

我的报告的输出[1]

How do I make the output easier for the end user to read?如何使最终用户更容易阅读输出?

The output is from version.changeset , which returns a hash .输出来自version.changeset ,它返回一个 hash You can loop through the hash to display each field and its changes on separate lines like so:您可以循环遍历哈希以在单独的行上显示每个字段及其更改,如下所示:

%td
  -version.changeset.each do |field, value|
    = field + ": "
    = value
    %br

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

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