Get will_paginate to define a custom offset on the first page?

Will_paginate redefines every 'offset' and 'limit' query conditions, to get the rows of a specific page. I can see two options for you.

Will_paginate redefines every 'offset' and 'limit' query conditions, to get the rows of a specific page. I can see two options for you : The ugly one : take advantage of the fact that will_paginate works on collections, and use this syntax (it will load all your table though) @news = Post. Offset(1).all.

Paginate(:page => params:page) The longer one : fork the will_paginate gem so that it can handle custom offsets. I haven't tried it, but something like this should work (the changes to the gem are highlighted) # will_paginate / lib / will_paginate / active_record. Rb module Pagination def paginate(options) options = options.

Dup pagenum = options. Fetch(:page) { raise ArgumentError, ":page parameter required" } per_page = options. Delete(:per_page) || self.

Per_page total = options. Delete(:total_entries) ####################################### custom_offset = options. Delete(:offset) ####################################### count_options = options.

Delete(:count) options. Delete(:page) ####################################################### # rel = limit(per_page. To_i).

Page(pagenum) rel = limit(per_page. To_i). Page(pagenum, custom_offset) ####################################################### rel = rel.

Apply_finder_options(options) if options. Any? Rel.

Wp_count_options = count_options if count_options rel. Total_entries = total. To_i unless total.

Blank? Rel end ################################ # def page(num) def page(num, custom_offset = 0) ################################ rel = scoped. Extending(RelationMethods) pagenum = ::WillPaginate::PageNumber(num.

Nil? 1 : num) per_page = rel. Limit_value || self.

Per_page ################################################################## # rel = rel. Offset(pagenum. To_offset(per_page).

To_i) rel = rel. Offset(pagenum. To_offset(per_page).

To_i + custom_offset) ################################################################## rel = rel. Limit(per_page) unless rel. Limit_value rel.

Current_page = pagenum rel end end This should allow you to use this syntax @news = Post. Paginate(:page => params:page, :offset => 1).

Awesome! Thanks! I created a fork if someone else needs this: https://github.Com/opetznick/will_paginate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions