From c27e3818fc106daed1aa6a58adc16d381143bbe3 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Wed, 29 Feb 2012 14:55:56 +0100 Subject: [PATCH] pagination --- .../stylesheets/public/articles.css.scss | 20 +++++++++++++++++++ app/controllers/public/articles_controller.rb | 6 ++++++ app/controllers/public/tags_controller.rb | 1 + app/views/public/articles/index.html.haml | 2 +- app/views/public/home/home.html.haml | 2 +- 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 app/assets/stylesheets/public/articles.css.scss diff --git a/app/assets/stylesheets/public/articles.css.scss b/app/assets/stylesheets/public/articles.css.scss new file mode 100644 index 0000000..75500fe --- /dev/null +++ b/app/assets/stylesheets/public/articles.css.scss @@ -0,0 +1,20 @@ +#articles_pagination{ + + margin-top:40px; + + a, .current{ + + display : inline-block; + padding:5px; + border:1px solid #82B139; + text-decoration:none; + + } + div{ + + padding-left:10px; + } + .current{ + border:none; + } +} \ No newline at end of file diff --git a/app/controllers/public/articles_controller.rb b/app/controllers/public/articles_controller.rb index 997da89..e1fc92f 100644 --- a/app/controllers/public/articles_controller.rb +++ b/app/controllers/public/articles_controller.rb @@ -7,6 +7,10 @@ class Public::ArticlesController < ApplicationController def index @articles = Article.recents + + @articles = @articles.page(params[:page]).per(10) + + @title = "Articles du blog" end @@ -17,6 +21,7 @@ class Public::ArticlesController < ApplicationController @category = Category.find_by_slug(params[:slug]) @articles = @category.articles.recents + @articles = @articles.page(params[:page]).per(10) @title = "Articles du blog" @index_title = 'Articles de la catégorie "'+@category.name+'"' render :action => :index @@ -26,6 +31,7 @@ class Public::ArticlesController < ApplicationController def archives @month = Date.parse("#{params[:year]}/#{params[:month]}").beginning_of_month @articles = Article.where("enabled = ? and published_at > ? and published_at < ?", true, @month, @month.end_of_month ) + @articles = @articles.page(params[:page]).per(10) @title = "Articles du blog" if [4,8].include?(@month.month) @index_title = 'Articles du mois d\''+l(@month, :format => "%B %Y")+'' diff --git a/app/controllers/public/tags_controller.rb b/app/controllers/public/tags_controller.rb index ca8b55c..5a23599 100644 --- a/app/controllers/public/tags_controller.rb +++ b/app/controllers/public/tags_controller.rb @@ -15,6 +15,7 @@ class Public::TagsController < ApplicationController if @tag @title = "tag : "+@tag.name.to_s @articles = @tag.recents_articles + @articles = @articles.page(params[:page]).per(10) render :template => "public/articles/index" else redirect_to "/", :notice => "La page que vous demandez n'a pas pu être trouvée.

Vous avez donc été redirigé sur notre page d'accueil" diff --git a/app/views/public/articles/index.html.haml b/app/views/public/articles/index.html.haml index 61be856..20125e7 100644 --- a/app/views/public/articles/index.html.haml +++ b/app/views/public/articles/index.html.haml @@ -6,7 +6,7 @@ -if @index_title %h1=@index_title =render :partial => "public/articles/article", :collection => @articles, :as => "article" - + #articles_pagination= paginate @articles -content_for :sidebar do diff --git a/app/views/public/home/home.html.haml b/app/views/public/home/home.html.haml index f67deb4..4bf9f04 100644 --- a/app/views/public/home/home.html.haml +++ b/app/views/public/home/home.html.haml @@ -33,7 +33,7 @@ -photos = photos.sort {rand(8)} -photos = photos.sort {rand(6)} -photos = photos.sort {rand(4)} - -photos = photos[0..5] + -photos = photos[0..4] -photos.each do |photo| .slide{:style => "width:1000px;height:460px;"}=link_to image_tag('diaporama/'+("%02d" % photo)+'.jpg', :style => "width:1000px;height:460px;"), ""