Giter Site home page Giter Site logo

Comments (6)

ryenski avatar ryenski commented on September 27, 2024 3

I have been using the edge version which includes #223 without problems. This changes the response to 422 Unprocessable Entity, which is compatible with Turbo.

gem 'responders', github: 'heartcombo/responders'

from responders.

mdavidn avatar mdavidn commented on September 27, 2024 3

This appears to fix the problem:

class ApplicationController < ActionController::Base
  # ...

  def redirect_to(url_options = {}, response_options = {})
    response_options[:status] ||= :see_other unless request.get?
    super url_options, response_options
  end
end

from responders.

carlosantoniodasilva avatar carlosantoniodasilva commented on September 27, 2024

Can you point to the docs where it mentions 303 only? I was under the impression that any redirect would do.

We do have an unreleased change on master about the 422 on errors: #223, I ran into a problem while testing it out and haven't been able to circle back on it again, but maybe that would help with what you're looking for?

from responders.

mrkcor avatar mrkcor commented on September 27, 2024

It is mentioned here: https://turbo.hotwire.dev/handbook/drive#redirecting-after-a-form-submission

422 responses work fine for me :)

from responders.

seyerian avatar seyerian commented on September 27, 2024

The issue remains that Turbo expects a 303 rather than redirect_to's 302. In particular, given:

class PostsController < ApplicationController
  ...
  def destroy
    @post.destroy
    respond_with(@post)
  end
end

On a successful DELETE:

  1. there are no model errors
  2. Responders redirects with 302 Location posts_path
  3. Turbo follows that as DELETE posts_path, which results in a routing error

Turbo's subsequent request is a DELETE (the original method) presumably because that is how fetch operates in conformance to the HTTP spec. See hotwired/turbo#84 (comment)

mrkcor's snippet in the OP fixes this issue between Responders and Turbo.

from responders.

mdavidn avatar mdavidn commented on September 27, 2024

This looks like a bug in Rails itself, in ActionController::Redirecting#redirect_to. 303 is the correct response code for a non-GET request if the client should use GET with the new location. This bug persists because all browsers (and curl -L) do not follow the spec and will change a POST into a GET after any redirect.

from responders.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.