Question

I am trying to create a view_all_page using Kaminari.

I have successfully installed the gem kaminariand using the kaminari THEME in twitter bootstrap.

I would like to create a view_all_page.html.erb to add to my app/views/kaminari theme.

Everything works great so far with my pagination, I just need to add a link/method to view all.

In my projects_controller.rb, under def index, I have @projects = Kaminari.paginate_array(@projects).page(params[:page]).per(10)

In my index.html.erb page I have <%= paginate @projects %>

In my app/views/kaminari folder I have _first_page, _gap, _last_page, _next_page, _page, _paginator, and _prev_page (.html.erb files)

I am looking to possibly customize the pagination helpers or figure out some logic to view all in my projects_controller.rb

Was it helpful?

Solution

You could set the params[:pagesize] to the count of all projects. Your view and controller might look something like this:

index.html.erb

<%=link_to "Show All", projects_path(:show_all => true) %>

projects_controller.rb

def index
  params[:pagesize] = params[:show_all] ? Projects.count : 10
  @projects = Kaminari
    .paginate_array(@projects)
    .page(params[:page])
    .per(params[:pagesize])
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top