Created
February 13, 2012 00:30
-
-
Save royw/1812150 to your computer and use it in GitHub Desktop.
Example code showing @pager.navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This gist originally showed the problem where I was not seeing the pagination navigation controls. | |
# This gist now shows how to correctly use pagination navigation controls. | |
# Thank you Yorick! | |
# Ramaze thread: http://groups.google.com/group/ramaze/browse_thread/thread/b40c827dce8d6ec1 | |
##### | |
# controller/init.rb: | |
class Controller < Ramaze::Controller | |
layout :default | |
helper :xhtml, :paginate, :gestalt | |
engine :etanni | |
end | |
Dir["#{__DIR__}/*.rb"].reject{|fn| File.basename(fn) == 'init.rb'}.each {|fn| require fn} | |
##### | |
# controller/hash_table.rb: | |
class HashTableController < Controller | |
map '/hash_table' | |
layout 'default' | |
def index | |
@title = 'HashTable' | |
@columns = HashTable.columns | |
@pager = paginate(HashTable, :limit => 5, :page => request.params['pager'].to_i) | |
end | |
end | |
##### | |
# view/hash_table.xhtml | |
<h3>#{@title}</h3> | |
<table> | |
<thead> | |
<tr> | |
<?r @columns.each do |column_name| ?> | |
<th>#{column_name}</th> | |
<?r end ?> | |
</tr> | |
</thead> | |
<tbody> | |
<?r @pager.each do |record| ?> | |
<tr> | |
<?r @columns.each do |column_name| ?> | |
<td>#{record.values[column_name]}</td> | |
<?r end ?> | |
</tr> | |
<?r end ?> | |
</tbody> | |
</table> | |
<p>#{@pager.navigation}</p> | |
##### | |
# model/init.rb | |
Dir["#{__DIR__}/*.rb"].reject{|fn| File.basename(fn) == 'init.rb'}.each {|fn| require fn} | |
##### | |
# model/hash_table.rb | |
# schema for legacy database: | |
#create table hash_table ( | |
# rowID bigserial not null, | |
# hash_key varchar(128) not null unique, | |
# hash_value varchar(16384), | |
# primary key (rowID) | |
#); | |
class HashTable < Sequel::Model(:hash_table) | |
end | |
##### | |
# app.rb | |
require 'rubygems' | |
require "bundler/setup" | |
require 'ramaze' | |
require 'pp' | |
require 'active_support/inflector' | |
require 'active_support/core_ext/string' | |
# Make sure that Ramaze knows where you are | |
Ramaze.options.roots = [__DIR__] | |
# use some legacy code to get database connection information | |
# internal gems | |
require 'ct_common' | |
# The CLUSTER environment variable should be set to the cluster.defaults file so environ.rb loads the manager DB info | |
require __DIR__('environ') | |
user = $db_user | |
password = $db_pass | |
host = $primary | |
port = 5432.to_s | |
database_name = $inst | |
require 'sequel' | |
DB = Sequel.connect("postgres://#{user}:#{password}@#{host}:#{port}/#{database_name}", | |
:max_connections => 10, :logger => Logger.new('log/db.log')) | |
Sequel.extension :pagination | |
# Initialize controllers and models | |
require __DIR__('model/init') | |
require __DIR__('controller/init') | |
##### | |
# Gemfile | |
source 'file:///Volumes/MacHD/Users/royw/gems-repo' | |
source 'http://rubygems.org' | |
gem 'ramaze', '= 2011.12.28' | |
gem 'bundler', '~> 1.0.21' | |
gem 'ct_common', '~> 0.0.4' | |
gem 'activesupport', '~> 3.2.1' | |
gem 'sequel', '~> 3.32.0' | |
gem 'pg', '~> 0.13.0' | |
group :development do | |
gem 'rspec', '~> 2.6.0' | |
gem 'bundler', '~> 1.0.21' | |
gem 'jeweler', '~> 1.6.4' | |
gem 'rdoc', '~> 3.9.4' | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment