-
Notifications
You must be signed in to change notification settings - Fork 77
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
Preserve user input when there are validation errors #1122
Merged
Merged
Conversation
This file contains 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
etiennebarrie
force-pushed
the
preserve-user-input
branch
from
November 20, 2024 15:16
d5d91e6
to
c6a0118
Compare
nvasilevski
approved these changes
Nov 21, 2024
adrianna-chang-shopify
approved these changes
Nov 21, 2024
task_name = params.fetch(:id) | ||
@task = TaskDataShow.new(task_name) | ||
@task.active_runs.load | ||
set_refresh if @task.active_runs.any? |
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 can remove set_refresh now, right?
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.
It's still used in tasks/index
.
etiennebarrie
force-pushed
the
preserve-user-input
branch
2 times, most recently
from
November 21, 2024 14:56
be7f450
to
5633221
Compare
Use a single instance variable to pass all the data that is needed for the view to render. This requires increasing the role of TaskDataShow to include preloading the active runs, and ensuring the Task exists, which was previously done in the controller action.
This preserves the user input while showing the validation errors.
Since a validation error results in the URL being shown in the address bar, it's a good practice to support the URL for GET requests. We just redirect back to the task page.
etiennebarrie
force-pushed
the
preserve-user-input
branch
from
November 21, 2024 14:57
5633221
to
538f09f
Compare
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.
Fix #1116
This allows preserving the data entered in the fields when there's a validation error and we're rendering the
maintenance_tasks/tasks/show
template.I tried using
TaskController.render(:show)
to be able to call thetasks/show
controller action directly, but I had issues with the flash (the flash is not used withActionController::Renderer
because it creates a fake request). We might be able to make this work, but instead, I decided to simplify the template by only requiring one instance variable to be passed into it, and then I was able to build the TaskDataShow in a different manner for the call site inruns#create
, and finally just render the template for the other action.I did use
flash.now
because we're now rendering the template directly instead of after a redirect. I also added a redirect forGET tasks/:task_id/runs
back to the task page.