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

Work with rails redirect #67

Closed
wants to merge 2 commits into from

Conversation

ConfusedVorlon
Copy link

This change was motivated by a notification in JumpstartRails
the notification is generated when someone makes a comment
I want the notification to redirect to a page - but to show the comments tab

e.g. I started with

 class NewComment < ApplicationNotification

...

  def url
    # You can use any URL helpers here such as:
    # post_path(params[:post])
    the_comment.commentable.public_url+"#comments"
  end

when the user clicks on the notification, the link is a get to

/notifications/:id
which redirects to
/resource#comments

this hits two problems:

  1. connect is called while the url is still /notifications/:id
    this is fixed by adding a listener for turbo:load

  2. even then, the hash part is lost
    this is fixed by allowing the format /resource?tab=comments

redirects in rails lose the bookmark element, using a param provides an alternative

e.g. http://localhost:3000/path?tab=comments
when the page is loaded by for example /notifications/17
and the rails controller redirects to
/page?tab=comments

then at the connect event, the url is still /notifications/17
we need to wait for the turbo:load to fire before the correct url is available
@ConfusedVorlon
Copy link
Author

@excid3 any comment on this?

@excid3 excid3 closed this Aug 3, 2023
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.

None yet

2 participants