使用Deface覆盖Spree Admin视图

时间:2014-12-05 20:52:01

标签: ruby-on-rails spree deface

我试图向Spree管理员添加几行。

文件我想覆盖:

backend/app/views/spree/admin/orders/_shipment.html.erb

我想在此处添加:

<tr class="show-tracking total">
        <td colspan="5" class="tracking-value">
          <% if shipment.tracking.present? %>
            <strong><%= Spree.t(:tracking) %>:</strong> <%= shipment.tracking %>
          <% else %>
            <%= Spree.t(:no_tracking_present) %>
          <% end %>
        </td>
      </tr>

我的覆盖是:

<!-- insert_after '.tracking-value' -->
</br>
<strong><%= Spree.t(:is_delivered) %>: </strong><%= shipment.is_delivered %></br>
  <% if shipment.date_delivered? %>
    <strong><%= Spree.t(:date_delivered) %>: </strong><%= shipment.date_delivered %></br>
  <% end %>

位于app/overrides/spree/admin/orders/shipment/add_tracking_info.html.erb.deface

内容:

</br>
<strong><%= Spree.t(:is_delivered) %>: </strong><%= shipment.is_delivered %></br>
  <% if shipment.date_delivered? %>
    <strong><%= Spree.t(:date_delivered) %>: </strong><%= shipment.date_delivered %></br>
  <% end %>

我想渲染:

<tr class="show-tracking total">
        <td colspan="5" class="tracking-value">
          <% if shipment.tracking.present? %>
            <strong><%= Spree.t(:tracking) %>:</strong> <%= shipment.tracking %>
            </br>
           <strong><%= Spree.t(:is_delivered) %>: </strong><%= shipment.is_delivered %</br>
          <% if shipment.date_delivered? %>
            <strong><%= Spree.t(:date_delivered) %>: </strong><%= shipment.date_delivered %></br>
          <% end %>
          <% else %>
            <%= Spree.t(:no_tracking_present) %>
          <% end %>
        </td>
      </tr>

非常感谢有关此问题的任何帮助,非常感谢!

1 个答案:

答案 0 :(得分:2)

你错过了一步。以非常抽象的方式,您需要告诉spree您需要插入的位置和内容。

Deface::Override.new(
  virtual_path: 'spree/admin/shared/_order_summary',    
  name:         'admin_order_custom_details',
  insert_after: 'header#order_tab_summary > dl.additional-info',
  partial:      'spree/admin/shared/admin_order_custom_details'
)

从我昨天工作的项目复制以下内容。它指示Deface添加部分'spree / admin / shared / admin_order_custom_details just after the dom element identified by标题#order_tab_summary&gt; dl.additional-info`。

所以我看到你需要做的是

  1. html.erb.deface更改为html.erb并将其移至某个位置app/views/spree/admin/orders/add_order_detials_to_shipment.html.erb
  2. app/overides/中创建一个新文件(扰流警报,使其成为有意义的警报或稍后后悔)
  3. 找到标识符(只是查看它,我认为它有点像erb[silent]:contains('if shipment.tracking.present?')
  4. 使用insert_bottom代替insert_after
  5. 我没有这样做,但我相信这就是你要找的。

    Deface::Override.new(
      virtual_path:  'app/views/spree/admin/orders/_shipment',    
      name:          'add_order_detials_to_shipment', # Or a fancy unique name
      insert_bottom: "erb[silent]:contains('if shipment.tracking.present?')",
      partial:       'app/views/spree/admin/orders/add_order_detials_to_shipment'
    )
    

    PS

    在阅读了文档的那部分后,我不知道有一个用于Deface的DSL,我认为你需要更新DSL这样

    <!-- insert_bottom "erb[silent]:contains('if shipment.tracking.present?')" -->
    </br>
    <strong><%= Spree.t(:is_delivered) %>: </strong><%= shipment.is_delivered %></br>
    <% if shipment.date_delivered? %>
      <strong><%= Spree.t(:date_delivered) %>: </strong><%= shipment.date_delivered %></br>
    <% end %>