diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index edd558933..9c7695b19 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -31,7 +31,7 @@ class AspectsController < ApplicationController @aspect_ids = @aspects.map{|a| a.id} @posts = StatusMessage.joins(:aspects).where(:pending => false, - :aspects => {:id => @aspect_ids}).includes(:comments, :photos, :likes, :dislikes).select('DISTINCT `posts`.*').paginate( + :aspects => {:id => @aspect_ids}).includes(:aspects, :post_visibilities, :comments, :photos, :likes, :dislikes).select('DISTINCT `posts`.*').paginate( :page => params[:page], :per_page => 15, :order => sort_order + ' DESC') @fakes = PostsFake.new(@posts) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d99e35036..b788191f9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,13 +21,13 @@ module ApplicationHelper def aspects_with_post aspects, post aspects.select do |aspect| - PostVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id) + aspect.has_post?(post) end end def aspects_without_post aspects, post aspects.reject do |aspect| - PostVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id) + aspect.has_post?(post) end end diff --git a/app/models/aspect.rb b/app/models/aspect.rb index b6a99cef8..77a371f37 100644 --- a/app/models/aspect.rb +++ b/app/models/aspect.rb @@ -21,6 +21,14 @@ class Aspect < ActiveRecord::Base name.strip! end + def has_post? post + post_ids = post_visibilities.each { |pv| pv.post_id } + post_ids.each { |id| + return true if id == post.id + } + return false + end + def to_s name end