Comments (6)
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.
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.
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.
It is mentioned here: https://turbo.hotwire.dev/handbook/drive#redirecting-after-a-form-submission
422 responses work fine for me :)
from responders.
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
:
- there are no model errors
- Responders redirects with
302
Locationposts_path
- 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.
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)
- Rails 6 RC1 HOT 1
- Doesn't Always Respect Domain Constraint HOT 2
- Template lookup order, and strict request format HOT 1
- Test Rails 6 with 2.4.x branch HOT 1
- private method `render' called HOT 2
- `redirect_to` cannot be called from `navigation_location` method HOT 3
- Errors not properly serialized in Rails API-Mode HOT 1
- Creating an object returns a 200 instead of a 201! HOT 1
- Turbo-streams and turbo-frames with responders HOT 15
- Explicitly set status gets overriden HOT 1
- undefined method `redirect_status'
- `location` compatibility with `allow_other_host` HOT 2
- New Release HOT 8
- Custom redirect_status only available when a flash YAML file exist HOT 5
- CodeClimate maintinability badge is not working
- Providing status as option doesn't work in 3.1.0 if has_errors?
- Namespaced Models and the Collection Responder
- Latest release does not show in releases tab HOT 1
- Minor: Release Notes for 3.1.1 are missing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from responders.