Learn how to redesign the post show page in Rails to enhance styling, navigation, and accessibility. This video covers refining post titles, action buttons, and comment layout while leveraging Rails helpers for a more readable and user-friendly interface. Follow along as we continue improving the UI and documenting changes for better usability.
Next up, let's turn our attention to the post show page.
If we look at our browser, it's pretty rough—there’s a lot we can do to improve the styling and usability of this page. Let's jump in and refine it step by step.
Enhancing the Post Title & Navigation
The first thing I want to do is add a standard title for the post card. Using the post title as our <h1>
tag seems like a great solution. Now, the post title is prominently displayed as an H1 heading.
Now let's improve the navigation on the “Back to Posts” link. It now has a left arrow icon and follows a more consistent style.
Optimizing Post Content & Formatting
Next, let’s clean up the post content layout:
- Used simple_format helper to ensure that new lines in the text area convert properly into paragraph tags.
- Moved edit and delete buttons for a better UX flow.
- Used Rails conditionals to structure the layout cleanly.
- Wrapped buttons in a div container for styling control.
- Applied button-like styling to links for consistency.
Adding Visual Hierarchy to Buttons
We want the delete button to stand out since it's a destructive action.
Created a dangerous class that:
- Uses red text and a red border.
- Turns fully red on hover.
Repositioned buttons horizontally with a flex container and gap spacing.
Improving Comment Section Layout
The comments section needed better separation from the post.
Added a horizontal rule (<hr>
)
- Styled it to match the outer border thickness.
- Used border-t-2 instead of a full border for a cleaner look.
Included metadata above the post:
- Displays the author’s name (or “you” if it's the logged-in user).
- Shows when the post was created, with a hoverable timestamp for exact time details.
- Uses a Rails helper (time_ago_in_words) for human-friendly readability.
- Links the comment count to jump directly to the comments section.
Adding Smooth Scroll for Comments
To ensure clicking the comment count link smoothly scrolls to the comments section:
- Wrapped comments in a
<div id="comments">
- Clicking the comment count now jumps directly to this section.
Refining the Comment Form
- Replaced the comment label with a placeholder inside the text field.
- Adjusted the width (w-2/3) for better visual balance.
- Added screen reader (sr-only) accessibility for hidden elements.
Now, the comment form is cleaner, more intuitive, and more accessible.
Final UI Polish
- Added spacing (space-y-4) between comments for better readability.
- Future improvements: Add metadata for comments (author, timestamp, etc.) in upcoming refinements.
- Committed all styling changes to the Git repository—you can follow along with the commits.
This update significantly improves the usability and aesthetics of the post show page, but there’s more UI polish to come.