我试图向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>
非常感谢有关此问题的任何帮助,非常感谢!
答案 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`。
所以我看到你需要做的是
html.erb.deface
更改为html.erb
并将其移至某个位置app/views/spree/admin/orders/add_order_detials_to_shipment.html.erb
app/overides/
中创建一个新文件(扰流警报,使其成为有意义的警报或稍后后悔)erb[silent]:contains('if shipment.tracking.present?')
insert_bottom
代替insert_after
我没有这样做,但我相信这就是你要找的。 p>
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'
)
在阅读了文档的那部分后,我不知道有一个用于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 %>