-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added pagination. #79
base: master
Are you sure you want to change the base?
Conversation
That's awesome, but let's use the kaminari gem instead of will paginate because it's actively maintained. Also please add a some tests (in |
Hi, Cezar, I changed the pagination gem to Kaminari, and wrote a Controller test in RSpec, but it's still not passing. Jake |
@@ -10,6 +10,9 @@ gemspec | |||
# Git. Remember to move these dependencies to your gemspec before releasing | |||
# your gem to rubygems.org. | |||
|
|||
gem 'kaminari' | |||
gem 'kaminari-rspec' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one should probably go in the test group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I added kaminari-rspec to the test group.
I added a paginate_posts_index_spec.rb feature test to the spec/features folder, which seems to be passing, but Kaminari's paginate method seems to be throwing errors across other tests.
I made changes to the Views, and ALL of the Features tests are passing (!!!)
@@ -4,7 +4,7 @@ class BlogPostsController < ApplicationController | |||
before_filter :find_blog_post!, :only => :show | |||
|
|||
def index | |||
@blog_posts = BlogPost.all | |||
@blog_posts = BlogPost.all.page(params[:page]).per(5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to call .all
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably have more than 5 posts on a page (.per(5)
). Also you should put the number in a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. No need to call .all
, and I set the number of posts per page to 10, in the config/initializers/kaminari_config.rb
file
I made suggested changes, but still need to revise the paginate posts spec file. The tests are all passing, however.
@@ -45,6 +45,8 @@ | |||
</tr> | |||
<% end %> | |||
</table> | |||
<% @blog_posts = BlogPost.page(params[:page]) %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blog_posts
is already set in the controller. You don't need to set it again in the view.
@@ -6,6 +6,7 @@ | |||
namespace :admin do | |||
resources :blog_posts do | |||
get "/get_tags" => "blog_posts#get_tags", as: :get_tags, on: :collection | |||
get '/blog/:page', :action => :index, :on => :collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to use the new hash syntax key: :value
instead of :key => :value
Hi, Cezar, |
Hi @chalmagean,
I added pagination via the will_paginate rubygem. Not sure if this is the route you wanted to go, but I guess it does the job.
Jake