thoughtbot / superglue

A productive library for Classic Rails, React and Redux
https://thoughtbot.github.io/superglue/
MIT License
327 stars 8 forks source link

Add warning when 406 response code is received #63

Closed jho406 closed 1 week ago

jho406 commented 3 weeks ago

When a Rails controller is setup with a respond_to like this

respond_to do |format|
  format.html
  format.csv
end

It take away the implicit rendering that happens when we do a regular render. To make this work with superglue remote calls like visit and remote, or data-sg-remote and data-sg-visit we also need to add format.json like so:

respond_to do |format|
  format.html
  format.json
  format.csv
end

If format.json isn't specified, rails will return a 406 response code. Right now, superglue doesn't know how to handle that since its a user error.

I'd like to add some handling for that so that when a 406 is present, i want to warn the user about what that error can be. Something like:

Superglue encountered a 406, this can happen if you used respond_to and didn't specify format.json in the block. Try adding it to your respond_to. For example:

respond_to do |format|
  format.html
  format.json
  format.csv
end

That would enhance the developer experience.