From 81eb66e02234ab86ad0f4a2d2d4cc90d275c103b Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Wed, 15 Aug 2012 15:58:19 +0100 Subject: [PATCH 1/2] Added pagination --- Gemfile | 1 + Gemfile.lock | 2 ++ app/assets/stylesheets/scaffolds.css.scss | 9 +++++++++ app/controllers/feeds_controller.rb | 1 + app/views/feeds/show.html.haml | 4 +++- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1516b7f..c8cfa75 100644 --- a/Gemfile +++ b/Gemfile @@ -43,3 +43,4 @@ gem 'mm-multi-parameter-attributes' gem 'feedzirra' gem 'htmlentities' gem 'sorcery' +gem 'will_paginate', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 8597b3e..3b01ee0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -146,6 +146,7 @@ GEM uglifier (1.2.5) execjs (>= 0.3.0) multi_json (~> 1.3) + will_paginate (3.0.3) PLATFORMS ruby @@ -163,3 +164,4 @@ DEPENDENCIES sass-rails (~> 3.2.3) sorcery uglifier (>= 1.0.3) + will_paginate (~> 3.0) diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss index 158a096..48e530d 100644 --- a/app/assets/stylesheets/scaffolds.css.scss +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -147,3 +147,12 @@ h2 { #userbar { background-color: #eee; } + +.pagination { + .current { + background-color: #00458F; + color: white; + font-style: normal; + padding: 3px; + } +} diff --git a/app/controllers/feeds_controller.rb b/app/controllers/feeds_controller.rb index 4cde975..0285077 100644 --- a/app/controllers/feeds_controller.rb +++ b/app/controllers/feeds_controller.rb @@ -17,6 +17,7 @@ class FeedsController < ApplicationController # GET /feeds/1.json def show @feed = Feed.find(params[:id]) + @posts = @feed.posts.paginate(:page => params[:page], :per_page => 20) respond_to do |format| format.html # show.html.erb diff --git a/app/views/feeds/show.html.haml b/app/views/feeds/show.html.haml index 47e981b..d9eac56 100644 --- a/app/views/feeds/show.html.haml +++ b/app/views/feeds/show.html.haml @@ -23,7 +23,7 @@ ago %table - - @feed.posts.each do |p| + - @posts.each do |p| %tr %td= link_to p.title, p.url %td= p.loc['lat'] @@ -32,6 +32,8 @@ - unless p.published.nil? = p.published.strftime("%d %b %Y %H:%M") += will_paginate @posts + = link_to 'Edit', edit_feed_path(@feed) \| = link_to 'Back', :root From 154341c7364a7e40604e97ccca821f29c7374cbd Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Wed, 15 Aug 2012 17:01:58 +0100 Subject: [PATCH 2/2] Sort posts by published date, most recent first --- app/controllers/feeds_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/feeds_controller.rb b/app/controllers/feeds_controller.rb index 0285077..77573f6 100644 --- a/app/controllers/feeds_controller.rb +++ b/app/controllers/feeds_controller.rb @@ -17,7 +17,7 @@ class FeedsController < ApplicationController # GET /feeds/1.json def show @feed = Feed.find(params[:id]) - @posts = @feed.posts.paginate(:page => params[:page], :per_page => 20) + @posts = @feed.posts.sort(:published.desc).paginate(:page => params[:page], :per_page => 20) respond_to do |format| format.html # show.html.erb