在 Rails 5.1 应用程序(启用 Turbolinks)中,我有以下表格
<%= form_with model: @role, url: admin_roles_path, method: :post do |f| %>
<%= f.text_field :name %>
<%= button_tag 'submit, type: 'submit' %>
<% end %>
以及相应的(虚拟)控制器
class Admin::RolesController < ApplicationController
def index
end
def new
@role = Role.new
end
def create
redirect_to admin_roles_path
end
end
不知道为什么,但重定向不起作用。admin/roles/index.js.erb
相反,控制器呈现。
更新我已经使用 webpacker 安装了 Turbolinks,并且来自文档
单独的 npm 包不提供对 Turbolinks 重定向的服务器端支持。有关添加支持的详细信息,请参阅以下重定向。
这把我带到了这里:https ://github.com/turbolinks/turbolinks#following-redirects
如何Turbolinks-Location
在 Rails 控制器内的最终响应中发送标头?