Skip to content
Snippets Groups Projects
Commit 1ce6ffba authored by Arnaud Levy's avatar Arnaud Levy
Browse files

Posts published in the future are indeed not published

parent 70136e11
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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>
......@@ -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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment