Skip to content
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

Merged
merged 1 commit into from
May 6, 2020

Conversation

skojin
Copy link
Contributor

@skojin skojin commented May 3, 2020

Implements #133

Tested on demo app.

Checklist

  • [ x] - An issue already exists detailing the issue/or feature request that this PR fixes
  • [ x] - All specs are formatted with crystal tool format spec src
  • [ x] - Inline documentation has been added and/or updated
  • [ x] - Lucky builds on docker with ./script/setup
  • [ x] - All builds and specs pass on docker with ./script/test

@wout
Copy link
Contributor

wout commented May 3, 2020

Will this possibly also fix #1093?

@skojin
Copy link
Contributor Author

skojin commented May 3, 2020

Will this possibly also fix #1093?

It looks like it fix, in my test app this problem is missing

Copy link
Member

@jwoertink jwoertink left a 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.

spec/lucky/action_redirect_spec.cr Outdated Show resolved Hide resolved
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Member

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

src/lucky/redirectable.cr Outdated Show resolved Hide resolved
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing this!

@skojin skojin force-pushed the turbolink-redirect branch from a43ad3d to 59732fc Compare May 3, 2020 17:49
* Handle Turbolinks-Location header in correct way
@skojin skojin force-pushed the turbolink-redirect branch from 59732fc to fc5212e Compare May 3, 2020 17:57
Copy link
Member

@paulcsmith paulcsmith left a 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"
Copy link
Member

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 :)

@paulcsmith paulcsmith merged commit 4a67c92 into luckyframework:master May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants