Open gallery attachment links in a new tab to avoid losing edits#1547
Draft
maebeale wants to merge 1 commit into
Draft
Open gallery attachment links in a new tab to avoid losing edits#1547maebeale wants to merge 1 commit into
maebeale wants to merge 1 commit into
Conversation
Clicking an attachment's filename in the image/gallery section of an edit form navigated away in the same tab, discarding unsaved form edits. Open these links in a new tab so in-progress work is preserved, matching how the show-page galleries already behave. Fixes #1511 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
maebeale
commented
Jun 5, 2026
| class="text-center text-sm text-gray-500 break-all max-w-[8rem]"> | ||
| <%= if blob.present? && blob.respond_to?(:persisted?) && blob.persisted? | ||
| link_to(blob.filename.to_s, url_for(file), class: "underline") | ||
| link_to(blob.filename.to_s, url_for(file), class: "underline", target: "_blank", rel: "noopener") |
Collaborator
Author
There was a problem hiding this comment.
This partial is rendered in every model's edit form via shared/_form_image_fields, so adding target: "_blank" here fixes the "navigates away and loses unsaved edits" report (#1511) across stories, resources, workshop variations, etc. in one place. Matches the new-tab behavior the show-page galleries already get from DisplayImagePresenter.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the shared gallery/attachment form partial so clicking an existing attachment’s filename opens the file in a new browser tab, preventing users from losing unsaved edits on the form.
Changes:
- Add
target="_blank"andrel="noopener"to the persisted attachment filename link inshared/_form_image_field. - Add a view spec to assert the filename link renders with the expected new-tab attributes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/views/shared/_form_image_field.html.erb | Updates the persisted attachment filename link to open in a new tab. |
| spec/views/shared/_form_image_field.html.erb_spec.rb | Adds coverage to ensure the filename link includes new-tab attributes. |
Comment on lines
82
to
84
| <%= if blob.present? && blob.respond_to?(:persisted?) && blob.persisted? | ||
| link_to(blob.filename.to_s, url_for(file), class: "underline") | ||
| link_to(blob.filename.to_s, url_for(file), class: "underline", target: "_blank", rel: "noopener") | ||
| else |
Comment on lines
+11
to
+13
| it "links the attached file's name so it opens in a new tab" do | ||
| expect(rendered).to have_css("a[href][target='_blank'][rel='noopener']", text: asset.file.filename.to_s) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1511
What is the goal of this PR and why is this important?
DisplayImagePresenter), but the in-form attachment cards (shared/_form_image_field) were missed — their filename link opened in the same tab.How did you approach the change?
target: "_blank", rel: "noopener"to the persisted-file filename link inapp/views/shared/_form_image_field.html.erb.spec/views/shared/_form_image_field.html.erb_spec.rb) that asserts the filename link opens in a new tab — confirmed it failed before the change and passes after.UI Testing Checklist
Anything else to add?