Skip to content

Commit

Permalink
Redirect to a reply's anchor when adding or removing a bookmark (#2410)
Browse files Browse the repository at this point in the history
* Redirect to a reply's anchor when adding or removing a bookmark

* Fix search test
  • Loading branch information
redmvc authored Jan 22, 2025
1 parent 65f64f8 commit 67af5ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create
flash[:error] = "Bookmark already exists."
end

redirect_back fallback_location: reply_path(@reply, anchor: "reply-#{@reply.id}")
redirect_to "#{request.referer || reply_path(@reply)}#reply-#{@reply.id}"
end

def destroy
Expand All @@ -72,7 +72,7 @@ def destroy
flash[:success] = "Bookmark removed."
end

redirect_back fallback_location: reply_path(@reply, anchor: "reply-#{@reply.id}")
redirect_to "#{request.referer || reply_path(@reply)}#reply-#{@reply.id}"
end

private
Expand All @@ -88,6 +88,6 @@ def bookmark_ownership_required
return if @bookmark.user.id == current_user.try(:id)

flash[:error] = "You do not have permission to perform this action."
redirect_back fallback_location: reply_path(@reply, anchor: "reply-#{@reply.id}")
redirect_to "#{request.referer || reply_path(@reply)}#reply-#{@reply.id}"
end
end
2 changes: 1 addition & 1 deletion spec/system/bookmarks/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def validate_bookmarks_found(bookmarks, posts, condensed: false)
# Can remove bookmark from search page
previous_path = current_url
find("a[href='#{bookmark_path(last_bookmark)}'][data-method='delete']").click
expect(page).to have_current_path(previous_path)
expect(page).to have_current_path(previous_path + "#reply-#{last_bookmark.reply.id}") # It redirects back with an anchor
expect(page).to have_no_selector(".bookmark-name[data-bookmark-id='#{last_bookmark.id}']")

# Can copy another user's bookmark
Expand Down

0 comments on commit 67af5ef

Please sign in to comment.