[openstreetmap/openstreetmap-website] Add a template for failed new diary comment validation (PR #4634)

Anton Khorev notifications at github.com
Fri Mar 29 10:36:01 UTC 2024


Here's a problem* that I came across when trying to create a controller for diary comments.

You write a comment for a diary entry, submit it and it fails the validation. Currently it's difficult to fail the validation, because empty comments are prevented client-side and it's difficult to type special characters that are disallowed. But let's suppose the validation failed. We have a branch for it:

https://github.com/openstreetmap/openstreetmap-website/blob/50df5eefcc5c45a47e1fcac50fe3ad6af6245819/app/controllers/diary_entries_controller.rb#L154

It just renders the diary entry page again. You'll be looking at the top of the page, not where the comment form is. And the entered comment is reset:

https://github.com/openstreetmap/openstreetmap-website/blob/50df5eefcc5c45a47e1fcac50fe3ad6af6245819/app/views/diary_entries/show.html.erb#L37

Here I'm showing a different page instead. It has a comment form that keeps the previously entered comment.

---

\* The actual problem was that with a diary comments controller I'd have to render the show action of another controller.
You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/4634

-- Commit Summary --

  * Add a template for failed new diary comment validation

-- File Changes --

    M app/controllers/diary_entries_controller.rb (2)
    A app/views/diary_entries/newcomment.html.erb (12)
    M config/locales/en.yml (2)
    M config/routes.rb (3)
    M test/controllers/diary_entries_controller_test.rb (4)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/4634.patch
https://github.com/openstreetmap/openstreetmap-website/pull/4634.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/4634
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/4634 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240329/abc946d0/attachment-0001.htm>


More information about the rails-dev mailing list