-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle Ajax form submission with Turbolinks (#133) #1133
Conversation
Will this possibly also fix #1093? |
It looks like it fix, in my test app this problem is missing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! It'll be nice to have this a little more solid. I'm not too familiar with turbolinks though, so I'm not sure what all is involved here. Looking at the linked issues to turbolinks and rails, this all looks good. I just left a few comments on things I'm wondering about.
context.response.headers.add "Turbolinks-Location", path | ||
context.response.status_code = status | ||
Lucky::TextResponse.new(context, "", "") | ||
if request.headers["X-Requested-With"]?.try(&.downcase) == "xmlhttprequest" && request.method != "GET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also do this same line here https://github.com/luckyframework/lucky/blob/master/src/lucky/mime_type.cr#L106. Maybe this can be used somehow? Or play back in to this thing https://github.com/luckyframework/lucky/blob/master/src/lucky/request_type_helpers.cr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first method is private
about second, it not works for me #1131
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skojin After this would you mind opening another PR that uses this logic for the ajax?
check? If not that's ok, just wondering :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
RedirectAction.new(context, params).call | ||
context.response.status_code.should eq 200 | ||
context.response.headers["Turbolinks-Location"].should eq "/somewhere" | ||
context.cookies.deleted?(:_turbolinks_location).should be_true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for testing this!
* Handle Turbolinks-Location header in correct way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fantastic. I think this is good to go, but want to give it another look before final merge.
Thank you so much!
context.response.headers.add "Turbolinks-Location", path | ||
context.response.status_code = status | ||
Lucky::TextResponse.new(context, "", "") | ||
if request.headers["X-Requested-With"]?.try(&.downcase) == "xmlhttprequest" && request.method != "GET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skojin After this would you mind opening another PR that uses this logic for the ajax?
check? If not that's ok, just wondering :)
Implements #133
Tested on demo app.
Checklist
crystal tool format spec src
./script/setup
./script/test