0

I am struggling with this. Using sinatra, ruby and Sequel, I attempting to implement paging.

The query is:

@items = DB[:candidates].order(:id).paginate(1, 10)

which works,it produces the desired number of records and the <%= will_paginate(@items) %> link generates the following HTML:

← Previous 1 2 3 4 5 Next →

When I click on the number or next link in my browser address bar I get, for exampl:

http://localhost:4567/candidate?page=3`

but the page does not change!

The ruby code is:

get '/candidate' do
      @items = DB[:candidates].order(:id).paginate(1, 10)
      erb :candidate
end

Any ideas? All help gratefully received. Is there a problem with param passing? The query

@items = DB[:candidates].order(:id).paginate(page: params[:page], 10)

does not work and produces an error message.

Thank you.

user1903663
  • 1,713
  • 2
  • 22
  • 44

1 Answers1

1

write the following code

@items = DB[:candidates].order(:id).paginate(:page=>params[:page] || 1, :per_page => 10)

and i the view file You write <%= will_paginate @items, :container => false %> instead of

@items = DB[:candidates].order(:id).paginate(1, 10)

And it works

Ravendra Kumar
  • 1,072
  • 10
  • 29
  • thank you, unfortunately it does not. This is the error: ArgumentError at /candidate wrong number of arguments (1 for 2) file: pagination.rb location: paginate line: 17 – user1903663 Jun 05 '13 at 05:58
  • <% @items.each do |item| %> <%= item[:designation] %> etc, other fields <% end %> <%= will_paginate(@items) %> – user1903663 Jun 05 '13 at 06:26
  • you write <%= will_paginate @items, :container => false %> in place of <%= will_paginate(@items) %> – Ravendra Kumar Jun 05 '13 at 06:28
  • thank you, same problem. Error message is: ArgumentError at /candidate wrong number of arguments (1 for 2) – user1903663 Jun 05 '13 at 06:43
  • http://thewebfellas.com/blog/2010/8/22/revisited-roll-your-own-pagination-links-with-will_paginate-and-rails-3 this link – Ravendra Kumar Jun 05 '13 at 06:45
  • thank you, I have seen something very similar already. It seems to be for active record rather than sequel. Am I wrong? I will study it again nonetheless. – user1903663 Jun 05 '13 at 06:49