You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When posting on a form enabled with data-sg-visit, the url changes the the received response's URL. For example, if you're on posts/new and the form does a POST to /posts to create a new post, its possible for the response to respond with a 200 because we may render errors. For example, in the controller:
def create
@post = Post.new
if @post.save
redirect_to post_path(@post)
else
# render errors
render :new
end
In this case the URL will change to /post, but will show the render of /posts/new which is incorrect. This happens with normal rails html too.
Superglue has a solution for this. If you add content-location to the headers, superglue will use that as the actual url. For example:
def create
@post = Post.new
if @post.save
redirect_to post_path(@post)
else
+ response.set_header("content-location", new_post_path)
render :new
end
this will tell Superglue.js to set the url to posts/new correctly when it receives the response from Rails.
issue
I'd like to be able to give the developer some console.info that they should use the above methodology when using data-sg-visit or visit.
We can detect the request method (non-Get), the response code, if it was a 200 (not redirected), check the headers for content-location, if its not there we console.info the following copy:
We recommend setting a content-location when using data-sg-visit or visit with a POST, PUT, or PATCH
The text was updated successfully, but these errors were encountered:
Context
When posting on a form enabled with
data-sg-visit
, the url changes the the received response's URL. For example, if you're onposts/new
and the form does a POST to/posts
to create a new post, its possible for the response to respond with a 200 because we may render errors. For example, in the controller:In this case the URL will change to
/post
, but will show the render of/posts/new
which is incorrect. This happens with normal rails html too.Superglue has a solution for this. If you add
content-location
to the headers, superglue will use that as the actual url. For example:def create @post = Post.new if @post.save redirect_to post_path(@post) else + response.set_header("content-location", new_post_path) render :new end
this will tell Superglue.js to set the url to
posts/new
correctly when it receives the response from Rails.issue
I'd like to be able to give the developer some
console.info
that they should use the above methodology when using data-sg-visit or visit.Maybe here:
superglue/superglue/lib/action_creators/requests.js
Line 96 in aaba7da
We can detect the request method (non-Get), the response code, if it was a 200 (not redirected), check the headers for content-location, if its not there we console.info the following copy:
The text was updated successfully, but these errors were encountered: