add author choice to posts page

This commit is contained in:
Skud committed 2013-07-26 14:55:47 +10:00
1 parent ebb8765583
commit ac684dd8ae
2 files changed
+24 -7

No files matched your search

+4
View File
@@ -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
+20 -7
View File
@@ -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