Leading:
app / Presenters / games_presenter.rb
class GamesPresenter attr_reader :games, :next_page, :previous_page def initialize json @games = json['machine-games'] paging = json['paging'] if paging && paging['next'] next_page_query = paging['next'].match(/\?.*/)[0] @next_page = "/machine_games/search#{next_page_query}" end if paging && paging['previous'] previous_page_query = paging['previous'].match(/\?.*/)[0] @previous_page = "/machine_games/search#{previous_page_query}" end end end
Controller action:
def show
Views:
<% @presenter.games.each do |game| %> ... <% end %> <%= link_to "Previous", @presenter.previous_page %> <%= link_to "Next", @presenter.next_page %>
And to tell Rails to load the apps / presenters / directory along with models /, controllers /, views, etc., add this to config / application.rb:
config.after_initialize do |app| app.config.paths.add 'app/presenters', :eager_load => true end
I just wanted to know how can I use will_paginate for the above case? Thank you.
source share