heartcombo / responders

A set of Rails responders to dry up your application
http://blog.plataformatec.com.br/
MIT License
2.05k stars 156 forks source link

Custom redirect_status only available when a flash YAML file exist #239

Closed taq closed 1 year ago

taq commented 1 year ago

I was having some issues with redirection on Firefox, getting a "Error: Form responses must redirect to another location" from turbo, and noticed that seems I needed a 302 redirect different status. As said on the README:

config.responders.redirect_status = :see_other

This would solve my problem, but I was not getting the custom redirect status working. I checked on console via

Rails.application.config.responders.redirect_status

And got :see_other, ok, but it was still not working (on Chrome everything was fine). Then I saw that on the responders.rb file ActionController::Responder.redirect_status is located inside the initializer "responders.flash_responder" block, setting the cattr_accessor :redirect_status. As I didn't have a flash YAML file, the default one installed with the generator is for en and I'm using pt-BR as my app language, I suppose the redirect_status attribute was never set.

When I created the pt-BR flash file, everything worked. So, I'm not sure if is just code on the wrong place, if the flash file is mandatory or I am missing something. Maybe running the app always with en set with the file created by the generator can miss this point on other languages.

Thanks!

taq commented 1 year ago

Uh, sorry. Seems even with the en file code was changed. But I still getting a Completed 302 Found when using respond_with after an update. Is there any way to force/check :see_other?

carlosantoniodasilva commented 1 year ago

@taq thanks for your report.

The redirect_status config should apply even though it's inside that initializer named responders.flash_responder, I believe that's just a naming that was used by the time since the only configs responders had were related to the flash responder, this is the first one that is for the responders themselves.

I was just testing redirect_status with a new error_status branch I'm working on https://github.com/heartcombo/responders/pull/240, and it appears to be working. I can change it via the config and restart Rails, which seems to pick up the change to the status I configure it to.

Which responders version are you using? The redirect_status is only on main, not a released version, so make sure you're pointing to that. (I hope to release a new version soon, once I finish my changes and ensure they're working as expected)

taq commented 1 year ago

Hey @carlosantoniodasilva , thanks for your answer.

Using responders (3.0.1)

carlosantoniodasilva commented 1 year ago

@taq gotcha, so redirect_status is really only available on main branch right now, I'm hoping to cut a new release soon. If you wouldn't mind giving that one a try, let me know if you run into any issues.

(You can also try out my branch if you want the 422 Unprocessable Entity behavior, by configuring error_status as well -- see the description there, it's going to main soon for the release I'm planning.)

taq commented 1 year ago

Thanks 👍🏻🙂