diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 4003d546a..b57c7b07e 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -8,6 +8,10 @@ class PostsController < ApplicationController def index @posts = Post.paginate(:page => params[:page]) + @author = Member.find_by_id(params[:author_id]) + if @author + @posts = @author.posts.paginate(:page => params[:page]) + end respond_to do |format| format.html # index.html.haml diff --git a/app/views/posts/index.html.haml b/app/views/posts/index.html.haml index 8d321f5ea..04fb34fdd 100644 --- a/app/views/posts/index.html.haml +++ b/app/views/posts/index.html.haml @@ -1,14 +1,27 @@ -= content_for :title, "Recent #{Growstuff::Application.config.site_name} member posts" +- content_for :title, @author ? "#{@author}'s posts" : "Everyone's posts" -%p= link_to 'Post something', new_post_path, :class => 'btn btn-primary' +%p + - if can? :create, Post + - if @author + %p + - if @author == current_member + = link_to 'Post something', new_post_path, :class => 'btn btn-primary' + = link_to "View everyone's posts", posts_path, :class => 'btn' + - else # everyone's posts + = link_to 'Post something', new_post_path, :class => 'btn btn-primary' + - if current_member + = link_to 'View your posts', posts_path(:author_id => current_member.id), :class => 'btn' + - else + = render :partial => 'shared/signin_signup', :locals => { :to => 'write a post' } %div.pagination = page_entries_info @posts, :model => "posts" = will_paginate @posts -- @posts.each do |post| - = render :partial => "single", :locals => { :post => post, :subject => true } +- unless @posts.empty? + - @posts.each do |post| + = render :partial => "single", :locals => { :post => post, :subject => true } -%div.pagination - = page_entries_info @posts, :model => "posts" - = will_paginate @posts + %div.pagination + = page_entries_info @posts, :model => "posts" + = will_paginate @posts