diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index fb5b7d9e337d0587af788a6c7efcfeadab96eff0..aa4143e902a6f1ce6381973061d73b5013146d0e 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -33,7 +33,12 @@ class Communication::Block::Template::Post < Communication::Block::Template def selected_posts_category quantity = data['posts_quantity'] || 3 - category.posts.ordered.limit(quantity) + category_ids = [category.id, category.descendants.map(&:id)].flatten + university.communication_website_posts.joins(:categories) + .where(categories: { id: category_ids }) + .distinct + .ordered + .limit(quantity) end def selected_posts_selection diff --git a/app/models/university/with_communication.rb b/app/models/university/with_communication.rb index c43441eb8296b3480d6994078aacc5c6eba5e12e..5dd2a35ba0a12770d34550ec521d462bc3d6bbfb 100644 --- a/app/models/university/with_communication.rb +++ b/app/models/university/with_communication.rb @@ -12,6 +12,10 @@ module University::WithCommunication dependent: :destroy alias_attribute :websites, :communication_websites + has_many :communication_website_posts, + class_name: 'Communication::Website::Post', + dependent: :destroy + has_many :communication_blocks, class_name: 'Communication::Block', dependent: :destroy diff --git a/app/views/admin/communication/blocks/templates/posts/_static.html.erb b/app/views/admin/communication/blocks/templates/posts/_static.html.erb index 959fad4a6f157971c86dcb5804efcd2f7dfe07f2..cf1ad033a4ef79c55eb17ac2f9d977de17536a4d 100644 --- a/app/views/admin/communication/blocks/templates/posts/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_static.html.erb @@ -1,5 +1,5 @@ <% if block.template.category %> - category: <%= block.template.category.slug %> + category: "<%= block.template.category.path %>" <% end %> posts: <% block.template.selected_posts.each do |post| %>