diff --git a/Gemfile b/Gemfile index 195e893..bfaffad 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,9 @@ gem 'sdoc', '~> 0.4.0', group: :doc gem 'twitter-bootstrap-rails' +gem 'will_paginate', '~> 3.0.6' +gem 'will_paginate-bootstrap' + # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index ce8cfa1..4676a3b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,6 +109,9 @@ GEM uglifier (2.5.3) execjs (>= 0.3.0) json (>= 1.8.0) + will_paginate (3.0.7) + will_paginate-bootstrap (1.0.1) + will_paginate (>= 3.0.3) PLATFORMS x86-mingw32 @@ -125,3 +128,5 @@ DEPENDENCIES twitter-bootstrap-rails tzinfo-data uglifier (>= 1.3.0) + will_paginate (~> 3.0.6) + will_paginate-bootstrap diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index 33a0433..e516ac4 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -4,7 +4,7 @@ class ProblemsController < ApplicationController # GET /problems # GET /problems.json def index - @problems = Problem.all + @problems = Problem.paginate(page: params[:page]) end # GET /problems/1 diff --git a/app/models/problem.rb b/app/models/problem.rb index 73e9c39..3d47698 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -1,4 +1,6 @@ class Problem < ActiveRecord::Base validates :title, :content, presence: true validates :title, uniqueness: true + + self.per_page = 50 end diff --git a/app/views/problems/_problem_pagination.html.erb b/app/views/problems/_problem_pagination.html.erb new file mode 100644 index 0000000..4df9095 --- /dev/null +++ b/app/views/problems/_problem_pagination.html.erb @@ -0,0 +1 @@ +<%= will_paginate @problems, renderer: BootstrapPagination::Rails %> \ No newline at end of file diff --git a/app/views/problems/index.html.erb b/app/views/problems/index.html.erb index c73c437..fd5875b 100644 --- a/app/views/problems/index.html.erb +++ b/app/views/problems/index.html.erb @@ -1,5 +1,6 @@

Listing problems

+<%= render 'problem_pagination' %> @@ -17,7 +18,7 @@ <% end %>
- +<%= render 'problem_pagination' %>
<%= link_to 'New Problem', new_problem_path, class: 'btn btn-default' %> diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..6fe1353 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,10 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +for i in 1..103 do + Problem.create( + title: "Problem Nummer #{i}", + content: "Das hier ist der Inhalt von Problem #{i}.
Hier ist die zweite Zeile." + ) +end \ No newline at end of file