我在 Rails 应用程序上,我使用 POST 请求从 CookiesController 触发操作。没什么特别的,但在使用 Safari 的最新 iPhone 上,这会触发文件下载邀请,我不明白为什么。
这是使用的代码。
<form action="<%= cookies_path %>" method="post" data-turbolinks="false">
<%= hidden_field_tag "authenticity_token", form_authenticity_token %>
<%= hidden_field_tag "cookie_accept", "true" %>
<button type="submit" style="all:unset;">
<div class="v_button_primary v_button__cookie">
<%= t('showcase.shared.button.accept') %>
<%= media_tag "images/arrow-white-right.png", alt: "icon-btn" %>
</div>
</button>
</form>
# Cookies
resources :cookies, only: [:create]
class CookiesController < ApplicationController
def create
if params[:cookie_accept] == "true"
cookies.permanent[:cookie_policy] = 'accepted'
head :no_content
elsif params[:legal_accept] == "true"
session[:legal_informations] = 'accepted'
head :no_content
else
head :bad_request
end
end
end
然后我在 ApplicationController 中有一些逻辑来检查 cookie before_action 并更新一个实例变量,例如显示或隐藏 cookie 模式。 如前所述,没什么特别的。
我不明白这里的问题是什么以及为什么会触发此行为,因为标头设置为“无内容”,有什么想法吗?