【发布时间】:2022-11-15 10:56:06
【问题描述】:
我想向未完成结帐的客户发送一封带有魔术链接的电子邮件,该链接将使他们在控制器中点击update 操作之前登录。
我在电子邮件正文中发送以下链接:
<%= link_to(
"Continue to checkout",
"#{checkout_url(host: @account.complete_url, id: @user.current_subscription_cart)}?msgver=#{@user.create_message_verifier}",
method: :patch,
subscription_cart: { item_id: @item_id },
) %>
我的checkouts_controller 有一个update 动作:
def update
# update cart with item_id param and continue
end
我的routes 看起来像这样:
resources :checkouts, only: [:create, :update]
它给出了以下update 路线:
checkout_path PATCH /checkouts/:id(.:format) checkouts#update
电子邮件正文中的 link_to 生成一个带有 data-method="patch" 属性的链接
<a data-method="patch" href="https://demo.test.io/checkouts/67?msgver=TOKEN">Continue to checkout</a>
=> https://demo.test.io/checkouts/67?msgver=TOKEN
但是当我点击它时,出现以下错误:
No route matches [GET] "/checkouts/67"
当我指定 method: :patch 时,为什么它会尝试 GET 请求?
【问题讨论】:
-
method: :patch需要rails-ujs才能正常工作。该库在用户接收电子邮件的电子邮件客户端中不可用。您应该假设发送给用户的电子邮件中的所有链接都是 GET 请求
标签: ruby-on-rails ruby routes