forked from OpenNeo/impress
pagination for results
This commit is contained in:
parent
a8318323ef
commit
3062dd9376
3 changed files with 6 additions and 1 deletions
|
@ -3,7 +3,7 @@ class ItemsController < ApplicationController
|
||||||
if params.has_key?(:q)
|
if params.has_key?(:q)
|
||||||
@query = params[:q]
|
@query = params[:q]
|
||||||
begin
|
begin
|
||||||
@results = Item.search(@query).alphabetize.all
|
@results = Item.search(@query).alphabetize.paginate :page => params[:page]
|
||||||
rescue
|
rescue
|
||||||
flash[:alert] = $!.message
|
flash[:alert] = $!.message
|
||||||
end
|
end
|
||||||
|
|
|
@ -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_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
|
set_inheritance_column 'inheritance_type' # PHP Impress used "type" to describe category
|
||||||
|
|
||||||
|
cattr_reader :per_page
|
||||||
|
@@per_page = 30
|
||||||
|
|
||||||
scope :alphabetize, order('name ASC')
|
scope :alphabetize, order('name ASC')
|
||||||
|
|
||||||
# Not defining validations, since this app is currently read-only
|
# Not defining validations, since this app is currently read-only
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
= form_tag items_path, :method => :get do
|
= form_tag items_path, :method => :get do
|
||||||
= text_field_tag :q, @query
|
= text_field_tag :q, @query
|
||||||
= submit_tag 'Search', :name => nil
|
= submit_tag 'Search', :name => nil
|
||||||
|
= will_paginate @results
|
||||||
= render @results
|
= render @results
|
||||||
|
= will_paginate @results
|
||||||
|
|
Loading…
Reference in a new issue