#275 - Admin Post CRUD & Ordering Enhancements #280
Merged
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.
address #275 first subtask - admin user can add a post with action text, but no upload image
This PR introduces several improvements and new features for managing posts via the admin interface. Key changes include:
Admin CRUD for Posts:
Administrators can now create, update, and view posts through a dedicated admin interface. The new views and controllers ensure a consistent, user-friendly experience for managing blog posts.
Custom Post Ordering:
The posts index now orders records using a SQL expression:
COALESCE(published_at, publish_scheduled_at) DESC NULLS LAST
followed by a secondary order on created_at DESC. This guarantees that posts are prioritized by the effective publish date, with unpublished posts (or those without dates) sorted at the bottom, and then by their creation time.
Friendly URLs & Slug Generation:
Posts now use FriendlyId for SEO-friendly URLs, with logic to generate slugs based on the published date and title.
Enhanced Validations & Enums:
The Post model now validates presence for key attributes and leverages enums for status (draft, scheduled, published, archived) and category (news, announcements).
Additional Refactoring:
Minor fixes to rubocop styles and unit tests ensure code quality and maintainability.
Add Blog url in menu
![blog](https://private-user-images.githubusercontent.com/3777577/411288994-10423f57-9acd-450d-8d46-9c4f82c44421.JPG?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NDMzNTEsIm5iZiI6MTczOTU0MzA1MSwicGF0aCI6Ii8zNzc3NTc3LzQxMTI4ODk5NC0xMDQyM2Y1Ny05YWNkLTQ1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yMjMwZjQzYzExZjI3MDg1NThmMTUwM2Q5MWFmNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.WrHnZoXeYw-ZID8qD-g8dcyB-6GdyB5B_ZpCWgeTpjg)
created a post
![create post2](https://private-user-images.githubusercontent.com/3777577/411289030-d5db0926-0990-4b61-ac50-ccace2270ef3.JPG?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NDMzNTEsIm5iZiI6MTczOTU0MzA1MSwicGF0aCI6Ii8zNzc3NTc3LzQxMTI4OTAzMC1kNWRiMDkyNi0wOTkwLTRiNjEtYWM1MC1jY2FjZTIyNzBlZjMuSlBHP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTRUMTQyNDExWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NTQzNDUwZDNiNzdmODIzM2EwMjBjM2FiNDU4YTUwMmE1YWFhYjY5ZDNiOTYwYWExOGQyYjIzN2RmNDg3OWM3OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.GV4eGFNztzeE88QHAS7RTZdzKdB6rh_OsRq1z-8TDDM)
list posts
![list posts](https://private-user-images.githubusercontent.com/3777577/411289036-25ea1990-bfdb-4c3f-9395-7b9f318b0d06.JPG?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOj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