From 30de08b340b0cf730c6a3625117f5601beb98b23 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Fri, 17 Feb 2012 17:51:50 -0800 Subject: [PATCH] fix post presenter / arrow ordering --- app/controllers/posts_controller.rb | 2 +- app/models/post.rb | 4 ++-- app/presenters/post_presenter.rb | 13 ++++++------- app/views/posts/show.html.haml | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 35e92274c..3b236925a 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -33,7 +33,7 @@ class PostsController < ApplicationController respond_to do |format| format.xml{ render :xml => @post.to_diaspora_xml } format.mobile{render 'posts/show.mobile.haml'} - format.json{ render :json => PostPresenter.new(@post).to_json } + format.json{ render :json => PostPresenter.new(@post, current_user).to_json } format.any{render 'posts/show.html.haml', :layout => 'layouts/post'} end diff --git a/app/models/post.rb b/app/models/post.rb index e8af5ca54..a3aa2ce93 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -69,11 +69,11 @@ class Post < ActiveRecord::Base } def self.next(post) - where("posts.id > ?", post.id) + where("posts.created_at > ?", post.created_at) end def self.previous(post) - where("posts.id < ?", post.id) + where("posts.created_at < ?", post.created_at) end def post_type diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index e44c2d1bf..7da227c9e 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -17,7 +17,7 @@ class PostPresenter } end - + def next_post_url if n = next_post Rails.application.routes.url_helpers.post_path(n) @@ -40,12 +40,11 @@ class PostPresenter protected - def post_base - scope = if current_user - Post.owned_or_visible_by_user(current_user) + def post_base + if current_user + current_user.posts_from(self.post.author) else - Post.all_public + self.post.author.posts.all_public end - scope.where(:author_id => post.author_id) end -end \ No newline at end of file +end diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index 1c9f0d1e5..bf4f3ce50 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -39,8 +39,8 @@ %i.icon-comment.icon-white -= link_to image_tag('arrow-left.png'), '#', :class => 'nav-arrow left', :id => 'back' -= link_to image_tag('arrow-right.png'), '#', :class => 'nav-arrow right', :id => 'forward' += link_to image_tag('arrow-left.png'), '#', :class => 'nav-arrow left', :id => 'forward' += link_to image_tag('arrow-right.png'), '#', :class => 'nav-arrow right', :id => 'back' #comment.modal.fade .modal-header