我正在尝试向 spree 管理页面添加一项功能以重新发送发货电子邮件。
我收到这个错误,
ActionView::Template::Error (undefined method `resend_shipment_email_admin_order_url' for #<#<Class:0x0000000668cf80>:0x00000006683700>):
16: </ul>
17:
18: <%= button_link_to Spree.t('Resend order email'), resend_admin_order_url(@order), method: :post, icon: 'email' %>
19: <%= button_link_to Spree.t('Resend shipment email'), resend_shipment_email_admin_order_url(@order), method: :post, icon: 'email'
%>
20: </div>
21: <% end %>
22: </div>
这是我的装饰器,app/controllers/spree/orders_controller_decorator.rb,
Spree::Admin::OrdersController.class_eval do
before_action :load_order, only: [:edit, :update, :cancel, :resume, :approve, :resend, :resend_shipment_email, :open_adjustments, :close_adjustments, :cart]
def resend_shipment_email
if @order.shipment_state == "shipped"
ShipmentMailer.shipped_email(@order.shipments.last.id).deliver
flash[:success] = "Shipment Email Resent"
redirect_to :back
else
flash[:error] = "Cannot send shipment email. Order not marked as shipped."
redirect_to :back
end
end
end
这是我的路线,
namespace :admin do
resources :orders, except: [:show] do
member do
post :resend_shipment_email
end
end
end
这是视图覆盖,
Deface::Override.new(:virtual_path => 'spree/admin/shared/_content_header',
:name => 'add_resend_shipment_email_button_to_spree_admin',
:insert_bottom => "[data-hook='toolbar'], #toolbar[data-hook]",
:text => "
<%= button_link_to Spree.t('Resend order email'), resend_admin_order_url(@order), method: :post, icon: 'email' %>
<%= button_link_to Spree.t('Resend shipment email'), resend_shipment_email_admin_order_url(@order), method: :post, icon: 'email' %>
"
)
这是 rake 路线的片段,
resend_shipment_email_admin_order POST /admin/orders/:id/resend_shipment_email(.:format) admin/orders#resend_shipment_email
resend_admin_order POST /admin/orders/:id/resend(.:format) spree/admin/orders#resend