diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index aa95abda1dddd39d7d1e3a7dada51ba12bc2c6f5..a4bdc69707a4f41ab87e12fe47f0c20d10ae64fc 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -13,6 +13,8 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati end def show + @pages = @website.pages.published.recent + @posts = @website.posts.published.recent breadcrumb end diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 7702f2fa24a04964af2406699a579c9c496b7f7b..c498286f6d5e7aea0c3f83c10b90468a6109328a 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -66,7 +66,18 @@ class Communication::Website::Post < ApplicationRecord before_validation :set_published_at, if: :published_changed? after_save_commit :update_authors_statuses!, if: :saved_change_to_author_id? - scope :published, -> { where(published: true) } + scope :published, -> { + where(" + communication_website_posts.published = true AND + DATE(communication_website_posts.published_at) <= now() + ") + } + scope :published_in_the_future, -> { + where(" + communication_website_posts.published = true AND + DATE(communication_website_posts.published_at) > now() + ") + } scope :ordered, -> { order(published_at: :desc, created_at: :desc) } scope :recent, -> { order(published_at: :desc).limit(5) } scope :for_author, -> (author_id) { where(author_id: author_id) } @@ -84,6 +95,10 @@ class Communication::Website::Post < ApplicationRecord ", term: "%#{sanitize_sql_like(term)}%") } + def published? + published && published_at.to_date <= Date.today + end + # Is it used? def path # used in menu_item#static_target diff --git a/app/views/admin/communication/websites/show/_pages.html.erb b/app/views/admin/communication/websites/show/_pages.html.erb index cbc93af84fa326ed0d8544f62078a06eb2cb5006..17fbbd2070b3ffa625d6fc21e8ac114d578e3991 100644 --- a/app/views/admin/communication/websites/show/_pages.html.erb +++ b/app/views/admin/communication/websites/show/_pages.html.erb @@ -15,5 +15,6 @@ <% end %> </h2> </div> - <%= render 'admin/communication/websites/pages/list', pages: @website.pages.recent %> + <%= render 'admin/communication/websites/pages/list', + pages: @pages %> </div> diff --git a/app/views/admin/communication/websites/show/_posts.html.erb b/app/views/admin/communication/websites/show/_posts.html.erb index d1d97da049fd65efe94398e424f9de5b5c935672..9f91cbbdc8c8cbd4a81185fbbf3d30c20c697b50 100644 --- a/app/views/admin/communication/websites/show/_posts.html.erb +++ b/app/views/admin/communication/websites/show/_posts.html.erb @@ -18,5 +18,8 @@ <% end %> </h2> </div> - <%= render 'admin/communication/websites/posts/list', posts: @website.posts.recent, hide_author: true, hide_category: true %> + <%= render 'admin/communication/websites/posts/list', + posts: @posts, + hide_author: true, + hide_category: true %> </div>