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
When a Rails controller is setup with a
respond_to
like thisIt take away the implicit rendering that happens when we do a regular
render
. To make this work with superglue remote calls likevisit
andremote
, ordata-sg-remote
anddata-sg-visit
we also need to addformat.json
like so:If
format.json
isn't specified, rails will return a406
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:
That would enhance the developer experience.