Skip to content

Commit

Permalink
added pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
wenbert committed Dec 24, 2011
1 parent 2a207da commit 348b976
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -7,6 +7,8 @@ gem 'rails', '3.1.3'

gem 'sqlite3'

#gem "will_paginate", :git => "https://github.com/p7r/will_paginate.git", :branch => "rails3"
gem 'will_paginate', '~> 3.0'

# Gems used only for assets and not required
# in production environments by default.
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -107,6 +107,7 @@ GEM
uglifier (1.2.0)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
will_paginate (3.0.2)

PLATFORMS
ruby
Expand All @@ -121,3 +122,4 @@ DEPENDENCIES
therubyracer
turn (= 0.8.2)
uglifier (>= 1.0.3)
will_paginate (~> 3.0)
4 changes: 3 additions & 1 deletion app/controllers/orders_controller.rb
Expand Up @@ -2,7 +2,9 @@ class OrdersController < ApplicationController
# GET /orders
# GET /orders.json
def index
@orders = Order.all
#@orders = Order.all
@orders = Order.paginate :page=>params[:page], :order=>'created_at desc',
:per_page => 10

respond_to do |format|
format.html # index.html.erb
Expand Down
1 change: 1 addition & 0 deletions app/views/orders/index.html.erb
Expand Up @@ -27,3 +27,4 @@
<br />

<%= link_to 'New Order', new_order_path %>
<p><%= will_paginate @orders %></p>
1 change: 1 addition & 0 deletions app/views/store/index.html.erb
Expand Up @@ -15,3 +15,4 @@
<pre>product.id => <%= product.id %></pre>
</div>
<% end %>

6 changes: 6 additions & 0 deletions script/load_orders.rb
@@ -0,0 +1,6 @@
Order.transaction do
(1..100).each do |i|
Order.create(:name => "Customer #{i}", :address => "#{i} Main Street",
:email => "customer-#{i}@example.com", :pay_type => "Check")
end
end

0 comments on commit 348b976

Please sign in to comment.