Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created April 4, 2011 08:52
Show Gist options
  • Save oelmekki/901313 to your computer and use it in GitHub Desktop.
Save oelmekki/901313 to your computer and use it in GitHub Desktop.
def index
@status = params[ :status ]
@status = 'all' unless %w(all mine flocks).include?( @status )
page = params[ :page ] || 1
if params[ :category ] and ( category = current_organization.categories.find_by_name( params[ :category ] ) )
blog_posts = category.blog_posts
else
blog_posts = current_organization.blog_posts
end
blog_posts = blog_posts.where( :published => true )
case @status
when 'mine':
blog_posts = blog_posts.where( :user_id => current_user.id )
end
if params[ :search ]
search = '%' + params[ :search ] + '%'
blog_posts = blog_posts.where( [ 'title like ? or content like ?', search, search ] )
end
blog_posts = blog_posts.order( 'created_at desc' )
@blog_posts = blog_posts.paginate( :page => page, :per_page => 3 )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment