Redirecting with Turbolinks via Webpacker

272 Views Asked by At

In a Rails 5.1 app (with Turbolinks enabled), I have the following form

  <%= form_with model: @role, url: admin_roles_path, method: :post do |f|  %>
    <%= f.text_field :name %>
    <%= button_tag 'submit, type: 'submit' %>
  <% end %>

And the corresponding (dummy) controller

class Admin::RolesController < ApplicationController
  def index
  end

  def new
    @role = Role.new
  end

  def create
    redirect_to admin_roles_path
  end
end

Not sure why but the redirect is not working. The controller renders admin/roles/index.js.erb instead.

UPDATE I have installed Turbolinks using webpacker and, from the doc

The npm package alone does not provide server-side support for Turbolinks redirection. See Following Redirects for details on adding support.

Which took me here: https://github.com/turbolinks/turbolinks#following-redirects

How can I send the Turbolinks-Location header in the final response from within the Rails controller?

0

There are 0 best solutions below