Scope querying in PhotosController#show

This commit is contained in:
Raphael Sofaer 2011-03-30 16:40:01 -07:00
parent 5fa2a7a6f3
commit e3ad078ba5
2 changed files with 5 additions and 5 deletions

View file

@ -139,7 +139,7 @@ class PhotosController < ApplicationController
end end
def show def show
@photo = current_user.find_visible_post_by_id(params[:id]) @photo = current_user.find_visible_post_by_id(params[:id], :type => 'Photo')
if @photo if @photo
@parent = StatusMessage.where(:id => @photo.status_message_id).includes(:photos).first if @photo.status_message_id @parent = StatusMessage.where(:id => @photo.status_message_id).includes(:photos).first if @photo.status_message_id

View file

@ -6,10 +6,10 @@ module Diaspora
module UserModules module UserModules
module Querying module Querying
def find_visible_post_by_id( id ) def find_visible_post_by_id( id, opts={} )
post = Post.where(:id => id).joins(:contacts).where(:contacts => {:user_id => self.id}).first post = Post.where(:id => id).joins(:contacts).where(:contacts => {:user_id => self.id}).where(opts).first
post ||= Post.where(:id => id, :author_id => self.person.id).first post ||= Post.where(:id => id, :author_id => self.person.id).where(opts).first
post ||= Post.where(:id => id, :public => true).first post ||= Post.where(:id => id, :public => true).where(opts).first
end end
def raw_visible_posts(opts = {}) def raw_visible_posts(opts = {})