From 3062dd9376abe63aa29f18d230be9ef88886b324 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 15 May 2010 14:14:17 -0400 Subject: [PATCH] pagination for results --- app/controllers/items_controller.rb | 2 +- app/models/item.rb | 3 +++ app/views/items/index.html.haml | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 3b9b5257..c419c5f4 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -3,7 +3,7 @@ class ItemsController < ApplicationController if params.has_key?(:q) @query = params[:q] begin - @results = Item.search(@query).alphabetize.all + @results = Item.search(@query).alphabetize.paginate :page => params[:page] rescue flash[:alert] = $!.message end diff --git a/app/models/item.rb b/app/models/item.rb index fde15689..e52c868c 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -2,6 +2,9 @@ class Item < ActiveRecord::Base set_table_name 'objects' # Neo & PHP Impress call them objects, but the class name is a conflict (duh!) set_inheritance_column 'inheritance_type' # PHP Impress used "type" to describe category + cattr_reader :per_page + @@per_page = 30 + scope :alphabetize, order('name ASC') # Not defining validations, since this app is currently read-only diff --git a/app/views/items/index.html.haml b/app/views/items/index.html.haml index 42252e9f..ec567706 100644 --- a/app/views/items/index.html.haml +++ b/app/views/items/index.html.haml @@ -1,4 +1,6 @@ = form_tag items_path, :method => :get do = text_field_tag :q, @query = submit_tag 'Search', :name => nil += will_paginate @results = render @results += will_paginate @results