Giter Club home page Giter Club logo

will_paginate's Introduction

will_paginate

will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, and Sequel.

gem 'will_paginate', '~> 4.0'

See installation instructions on the wiki for more info.

ℹ️ will_paginate is now in maintenance mode and it will not be receiving new features. See alternatives

Basic will_paginate use

## perform a paginated query:
@posts = Post.paginate(page: params[:page])

# or, use an explicit "per page" limit:
Post.paginate(page: params[:page], per_page: 30)

## render page links in the view:
<%= will_paginate @posts %>

And that's it! You're done. You just need to add some CSS styles to make those pagination links prettier.

You can customize the default "per_page" value:

# for the Post model
class Post
  self.per_page = 10
end

# set per_page globally
WillPaginate.per_page = 10

New in Active Record 3:

# paginate in Active Record now returns a Relation
Post.where(published: true).paginate(page: params[:page]).order(id: :desc)

# the new, shorter page() method
Post.page(params[:page]).order(created_at: :desc)

See the wiki for more documentation. Report bugs on GitHub.

Happy paginating.

will_paginate's People

Contributors

benpickles avatar bryanlarsen avatar chandresh avatar chriseppstein avatar coderhs avatar danielvartanov avatar dbackeus avatar dejan avatar denis avatar dhh avatar dnrce avatar edariedl avatar elengine avatar fabioyamate avatar flyingmachine avatar fwininger avatar gcirne avatar kamal avatar kjg avatar mattetti avatar metaskills avatar mislav avatar nathany avatar olleolleolle avatar orien avatar phene avatar phoffer avatar poporul avatar tenderlove avatar useruby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

will_paginate's Issues

Overzealous match with finder.rb#method_missing_with_paginate?

I am seeing an issue with 2.3.11 under rspec with rails 2.3.5. Given I have an activerecord class with a method containing the word 'paginate':

class Foo << ActiveRecord::Base; def self.paginated_search; end; end

..when attempting to call that method in specs I will be told:

"undefined method ‘findd_search’ for #Class:0x60f2c"

I have traced this down to Finder module in #method_missing_with_paginate where it appears to be patching ActiveRecord's base with a method missing that is calling .sub on the method name that replaces 'paginate' with 'find' and is changing my method call to 'findd_search' (which doesn't exist, of couse)

I have been able to fix problems in my local install by either changing the method name to be something that doesn't contain the word 'paginate' or by patching the method_missing.

For the next version of will_paginate, might it be a good change to switch:

finder.rb:175:
finder = method.to_s.sub('paginate', 'find')

to something like:
finder = method.to_s.sub(/^paginate_/, 'find_')

..so that it will only match methods named "paginate_*" and not methods named "is_paginated_*".

Removing next link causes last page to repeat

There seems to be a problem when you remove the next link by setting the next_link parameter to nil on the will_paginate method.

It seems to result in the link for the last page being repeated.

For example:
« Previous 1 2 2

will_paginate helpers and edge rails

hi,
Rails changed default html rendering to "safe mode" by default, escaping html chars, etc.

Result:

Displaying Records <b>1&nbsp;-&nbsp;30</b> of <b>414</b> in tot...

Add rel attributes to pagination links

The Atom link relations standard establishes four rel attribute values that are relevant to will_paginate. Though they are defined for ATOM and not HTML pages, I suspect they might be valuable here as well (particularly if someone were embedding HTML in an ATOM feed). Specifically, they are

rel="first"
rel="previous"
rel="next"
rel="last"

Offsets wrong under certain circumstances

Following steps drive to wrong counting of the entries:
* 50 entries
* set per_page to 25
* set page to 2
* set per_page to 100
Then the offset is 100, though it should be 1.
So there should be a fix for this situation.
I did an ugly monkeypatch:

module PaginateActiveRecordPatch
  def self.extended base
    def wp_parse_options(options) #:nodoc:
      raise ArgumentError, 'parameter hash expected' unless options.respond_to? :symbolize_keys
      options = options.symbolize_keys
      raise ArgumentError, ':page parameter required' unless options.key? :page
      if options[:count] and options[:total_entries]
        raise ArgumentError, ':count and :total_entries are mutually exclusive'
      end 

      page     = (options[:page] || 1).to_i.abs
      per_page = options[:per_page] || self.per_page
      total    = options[:total_entries]
      #############################################################################################
      max = total || count(options.except :page, :per_page, :total_entries, :finder, :order, :count)
      max_page = ((max <= 0 ? 1 : max).to_f / per_page.to_i).ceil.to_i 
      page = max_page if page.to_i > max_page
                #############################################################################################
        [page, per_page, max]
    end 
    end 
end 
ActiveRecord::Base.send(:extend, PaginateActiveRecordPatch)

The same issue with the extension of class Array:

Array.class_eval do
def paginate(options = {}) 
    raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options
  total_entries = options[:total_entries] || self.length
  per_page = options[:per_page] || 30
    page = options[:page] || 1
        ############and again: ##############################
    max_page = ((total_entries <= 0 ? 1 : total_entries).to_f / per_page.to_i).ceil.to_i 
    page = max_page if page.to_i > max_page
        #############################################################################################
    WillPaginate::Collection.create(page, per_page, total_entries) { |pager|
    pager.replace self[pager.offset, pager.per_page].to_a
    }   
  end 
end

This monkeypatch is just for better explanation of the issue I've got. And it's definitely not a solution.
To me the location for the recalculating should take place in Collection#create, but for this I'd have to rewrite a little more. Unfortunately the ActiveRecord#count is done after the finder itself in Finder#paginate. That makes it ugly to fix it with a plugin upon it. I'd prefer a redesign of the counting. If you agree, I'd code it.

At the end I want to thank you for your massive engagement into this awesome plugin.

Best regards
Chris

undefined method `validation_group'

hi, one of my forms is calling will paginate code and I get this on my mac OS
NoMethodError (undefined method validation_group' for #<Class:0x26b3864>): /Library/Ruby/Gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:170:inmethod_missing'
app/models/export_request.rb:90

It works under Linux though so I believe it is an environment issue. Any help to help troubleshoot woud be great.
Thanks

Here is my gem list

actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.4, 2.3.2)
activerecord-jdbc-adapter (0.9.3)
activerecord-jdbcmysql-adapter (0.9.3)
activeresource (2.3.2)
activesupport (2.3.5, 2.3.4, 2.3.2)
allison (2.0.3)
authlogic (2.0.13)
aws-s3 (0.6.2)
builder (2.1.2)
composite_primary_keys (2.3.2)
cucumber (0.3.96)
daemons (1.0.10)
dbi (0.4.3)
deprecated (2.0.1)
diff-lcs (1.1.2)
echoe (4.3)
fastercsv (1.5.0)
gemcutter (0.5.0)
jdbc-mysql (5.0.4)
jruby-openssl (0.6)
json_pure (1.2.3)
mime-types (1.16)
mislav-will_paginate (2.3.11)
polyglot (0.3.1)
rack (1.0.1)
rails (2.3.2)
rake (0.8.7)
redis (0.2.0)
redis-namespace (0.4.0)
resque (1.6.1)
rspec (1.2.9)
ruby-ole (1.2.10.1)
rubyforge (2.0.4)
rubygems-update (1.3.6)
rubyzip (0.9.1)
rvm (0.1.5)
sinatra (1.0)
sources (0.0.1)
spreadsheet (0.6.4.1)
term-ansicolor (1.0.5)
thrift_amqp_transport (0.1.0)
treetop (1.4.5)
vegas (0.1.5)
will_paginate (2.2.2)
wizardly (0.1.8.9)
xml-simple (1.0.12)

`page_entries_info` i18n support

Hello mislav,

Is fully I18n support in todo list of will_paginate?

I'm using will_paginate with in some sites which needs to be internationalized.

Thanks

Active Record 3 query interface doesn't work with will_paginate

Active record query interface changed alot since it used arel and brought lots of conveniences to developers. For instance we can now do this:
@features = @project.features @features = @features.where(['user_story like ?', conditions[:user_story]])

But if we do this with will_paginate:
@features = Feature.paginate(:page => params[:page], :order => 'id DESC', :per_page =>1, :conditions => conditions) @features = @features.where(['user_story like ?', conditions[:user_story]])

It will throw this error:
undefined methodwhere' for #WillPaginate::Collection:0xc7e2508`

Default :previous_label and :next_label break under Rails3

Rails3 includes some new html and json safety that prevents '&', '<', and '>' characters passing unmodified as link_to labels. See ActionView::Erb::Util HTML_ESCAPE{} for details. End result is that link_to "« Previous" comes out on the screen as "&laquo; Previous".

Why is :page required?

If the :page variable is nil it defaults to 1. Yet you're still required to pass it.

Why is this? Not passing any judgement either way, just seems like a weird api.

I'm going to monkey-patch mine to not do this, but am wondering if there's something I'm missing.

count(*) problem with postgres.

This plugin don't works with postgres for some queries that have distinct and selecting more than one column because Postgres follow sql standard strictly and mysql added few things in sql. If you change the count query using subquery then it will work fine for both of them mysql and postgers. Now plugin do following things in case of mysql and postgres.Here is example.

Mysql ::
Regular query ::
SELECT DISTINCT tenders.* FROM tenders INNER JOIN assignments ON tenders.id = assignments.assignable_id AND assignments.assignable_type = 'Tender'

Count query ::
SELECT count(DISTINCT tenders.id) AS count_distinct_tenders_id FROM tenders INNER JOIN assignments ON tenders.id = assignments.assignable_id AND assignments.assignable_type = 'Tender'

Postgres ::
Regular query ::
SELECT DISTINCT "tenders".* FROM "tenders" INNER JOIN "assignments" ON "tenders".id = "assignments".assignable_id AND "assignments".assignable_type = E'Tender'

Count query ::
SELECT count(DISTINCT "tenders".*) AS count_distinct_tenders_all FROM "tenders" INNER JOIN "assignments" ON "tenders".id = "assignments".assignable_id AND "assignments".assignable_type = E'Tender'

This count query of postgres gives following error "PGError: ERROR: could not identify an equality operator for type tenders". As per postgres documentation you can only give one expression to count function which is sql standard but mysql allows more than one expressions in count(*) function. If you transform this query using this then it will work for both.

SELECT count() from(
SELECT DISTINCT "tenders".
FROM "tenders" INNER JOIN "assignments" ON "tenders".id = "assignments".assignable_id AND "assignments".assignable_type = E'Tender' ) as temp

I also tried new count query way with sqlite and it worked so we are safe to implement for sqlite,mysql and postgres.

Thanks
Junaid.

Page Count wrong and whacky with complex query..

Here's the actual call to AR:
@hidden_topics = @band.topics.most_hidden_since(hidden_topics_date).paginate :page => params[:page]

Here's the named scope:
named_scope :most_hidden_since, lambda {|since| {
:joins => :hidden_topics,
:having => 'count(hidden_topics.id) > 0',
:group => 'topics.id',
:conditions => ['created_at > ?', since],
:order => 'count(hidden_topics.id) desc' } }

(This mess sorts by the count of the has_many association)

The page count was 7 on some pages and 4 on others.. The Patch that was posted here last march fixed my problem :

http://groups.google.com/group/will_paginate/browse_thread/thread/3b902e23e01e1ec9?pli=1

Thanks.

support of named_scopes with arguments

I have a model Article connected with a model Shop via has_many :through and a join table. To lookup articles contained in a specific shop, I use a named_scope :for_shop, lambda { |shop_id| ...} to make the query more transparent.

When I call the magic finder method paginate_for_shop (which requires renaming for_shop to find_for_shop), will_paginate passes the complete parameter array to this finder method which results in an error.

I found a workaround involving proxy_options, but something like paginate_scoped :scope_name, scope_arg, :page=>... would be nice to have.

The Google group contains more details and some code snippets, cf http://bit.ly/aOAgxb

Kind regards

Leonhardt

Rails 2.3.7 breaks will_paginate output

After switching my application to 2.3.7 (+ the rails_xss plugin), will_paginate outputs escaped HTML code. Filtering through the "raw" helper does not help.
2.3.6 works just fine.

WillPaginate::Finder::ClassMethods::paginate not being discovered

I posted this on the railsforum too before I discovered this - but it seems the function paginate is not being recognized - but the rest are (eg, paginate_by_sql). To remedy the issue i did 2 things:

I had to put this extra line in lib/will_paginate.rb

ActiveRecord::Base.extend(WillPaginate::Finder::ClassMethods) or else the additional class methods won't be found.

Next, i change the function name "paginate" to "paginate_result" and that seemed to do the trick.

Perhaps a name clash or something, I would be happy to discover the root of this problem and a possible solution if someone can give suggestions.

Meddling with Date ?

I can't seem to find anything related to Date within will_paginate itself, which seems great; but fwiw Date.today's behavior seems to be changed once I required will_paginate (2.3.11). See : http://pastie.org/553050

I am under-caffeinated atm, though. So this may be completely unrelated. ^^;

Finder.wp_count remove need group by option so returns invalid value

Hi,

Here is the requests generated and showing the issue :

Author Load (1.3ms) SELECT users., COUNT(1) AS count FROM users INNER JOIN posts ON posts.author_id = users.id WHERE ( (users.type = 'Author' ) ) GROUP BY posts.author_id LIMIT 2, 2
SQL (0.2ms) SELECT count(
) AS count_all FROM users INNER JOIN posts ON posts.author_id = users.id WHERE ( (users.type = 'Author' ) )

In this case the GROUP BY as been removed but should have been kept to return the right number of results.

ERROR: Permission to mislav/will_paginate denied to [user].

Hi!

I'm trying to use will_paginate in a Rails 3 application using Bundler for gem/dependency management.

I've used the following configuration for some time, which recently stopped working giving me an error message:

gem "will_paginate", :git => "git://github.com/mislav/will_paginate.git",  :branch => "v3.0.pre"

which results in the following error:

ERROR: Permission to mislav/will_paginate denied to frw.
fatal: The remote end hung up unexpectedly
Clone of '[email protected]:mislav/will_paginate.git' into submodule path 'website' failed

Return of stack level too deep bug

Hello,

I'm getting a method missing error when I attempt to destroy a record.

def destroy
@person = Person.find(params[:id])
@person.destroy

respond_to do |format|
  format.html { redirect_to(people_url) }
  format.xml  { head :ok }
end

end

produces:
SystemStackError in PeopleController#destroy

stack level too deep

/usr/local/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:168:in `method_missing'

Running will_paginate (2.3.12) with Rails 2.3.4. has_many :through relationships in the Person model.

A bunch of the forums suggested updating my gem, but I believe I'm using the latest version.

Thanks!

View All link helper?

Is there a helper for generating a View ALL link that works well with will_paginate?

Finder.wp_count use invalid select option and breaks counting request

Hi,

Here we go with the second issue regarding the counting request :

SELECT count(users.*, addresses.full_address) AS count_users_all_addresses_full_address FROM ...

This case actually breaks.
Looks like the select option could have been replaced to produce the following request and work as expected :

SELECT COUNT(1) AS count_all FROM ...

Right now I work around this issue using the :count option of paginate but doesn't feel natural.
Let me know if you need further details.

P.S. : a BIG thanks for this wonderful gem.

Large Database Stack Level Too Deep

Reported by Ron Valente with mislav-will_paginate v2.3.11

466992 rows in set (0.97 sec)

>> h = Host.paginate :per_page => 15, :page => 1

SystemStackError: stack level too deep

Ruby Versions - Same Error On Both

  1. ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]
  2. ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9]

gem install bug

config.gem "mislav-will_paginate", :lib => "will_paginate", :version => "~> 2.3",

should change to

config.gem "mislav-will_paginate", :lib => "will_paginate", :version => "~> 2.3", :source => 'http://gems.github.com'

hehe:) easy to change..

Pagination links should be marked as HTML safe

Using Rails 2.3.5 and the rails_xss plugin, the pagination links are not marked as HTML safe, so are escaped and do not display correctly. It seems like they should be marked using html_safe! by default if it is available?

Paginating a has_many :through with :uniq => true breaks under PostgreSQL

Given a has_many :through with :uniq => true set, attempting to paginate the relationship will raise the error "could not identify an equality operator for type" under PostgreSQL.

The Finder class in WillPaginate has this line:

      if options[:select].gsub('`', '') =~ /\w+\.\*/

The gsub is supposed to remove the quoting from the sql fragment, but PostgreSQL uses " as the quote operator for table/column names. Changing this line to:

      if options[:select].gsub(/[`""]/m, '') =~ /\w+\.\*/

Fixes the problem.

externally created models not listed in paginate until after running Model.find

I'm using will_paginate version 2.3.12

I built a rails(2.1.0) app to manage data being persisted by an external application. However, data added by the external app does not appear in paginated results, unless the corresponding models are first accessed by other rails means (e.g. via MyModel.find).

It seems like a caching problem.

steps to repeat:

  1. Insert a row into the my_models table via dbconsole
  2. run MyModel.paginate(...) # doesn't include the new model
  3. MyModel.find(:all) # cache updated?
  4. MyModel.paginate(...) #does include new model

page_entries_info with :per_page => 1

first of all thanks for sharing this great stuff. I am using this, amongst others, to skip through a stock of input forms of the same type. That means I am showing only 1 item per page and the user is able to jump or skip through the whole stock. To improve the visualisation I had to change your code of "page_entries_info" like that:

  if collection.length == 1
    %{Displaying #{entry_name} <b>%d</b> of <b>%d</b> in total} % [
      collection.offset + 1,
      collection.total_entries
    ]
  else
    %{Displaying #{entry_name.pluralize} <b>%d&nbsp;-&nbsp;%d</b> of <b>%d</b> in total} % [
      collection.offset + 1,
      collection.offset + collection.length,
      collection.total_entries
    ]
  end

Maybe you like to change this as well for others.

Using custom SELECT results in invalid SQL

I'm using a custom SELECT to calculate a difference between to datetimes, which I want to use as a sort/filter condition using Will_Paginate. However, Will_Paginate doesn't account for a custom SELECT field when running the COUNT query, resulting in invalid SQL.

The code I'm using is the following;
if RAILS_ENV != "production"
select = ", strftime("%s",COALESCE(activities.stop, 'now')) - strftime("%s",activities.start) as duration"
else
select = "
, UNIX_TIMESTAMP(COALESCE(activities.stop, now())) - UNIX_TIMESTAMP(activities.start) as duration"
end

condition = self.conditions(filter)
paginate(
  :select => select,
  :order => PageMethods.sort_order(%w{projects.name start stop duration}, sort ? sort : 'start_reverse', 'start'),
  :conditions => condition,
  :include => [:project, {:project => :client}],
  :per_page => limit,
  :page => page)

And the error generated SQL/error;

SQLite3::SQLException: no such column: duration: SELECT count(*) AS count_all FROM "activities" WHERE (duration < '5') AND ("activities".user_id = 1)

D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract_adapter.rb:212:in log' D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/sqlite_adapter.rb:160:inexecute'
D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/sqlite_adapter.rb:405:in catch_schema_changes' D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/sqlite_adapter.rb:160:inexecute'
D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/sqlite_adapter.rb:308:in select' D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/database_statements.rb:7:inselect_all_without_query_cache'
D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in select_all' D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/query_cache.rb:81:incache_sql'
D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in select_all' D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/database_statements.rb:13:inselect_one'
D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/database_statements.rb:19:in select_value' D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/calculations.rb:235:inexecute_simple_calculation'
D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/calculations.rb:134:in calculate' D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/calculations.rb:130:incatch'
D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/calculations.rb:130:in calculate' D:/software/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/calculations.rb:48:incount'
D:/software/ruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:223:in wp_count' D:/software/ruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:235:incall'
D:/software/ruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:235:in wp_count' D:/software/ruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:85:inpaginate'
D:/software/ruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/collection.rb:87:in create' D:/software/ruby/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:76:inpaginate'
D:/web/Another/app/models/activity.rb:68:in search' D:/web/Another/app/controllers/activities_controller.rb:126:infind_activities'

undefined method `returning' for WillPaginate:Module

$ rails plugin git://github.com/joshmh/globalize2.git
/home/wr/.rvm/gems/ree-1.8.7-2010.01/gems/will_paginate-2.3.14/lib/will_paginate.rb:39:in enable_activerecord': undefined methodreturning' for WillPaginate:Module (NoMethodError)

ree-1.8.7-2010.01

problem with declarative_authorization (named_scope, joins?)

Using declarative_authorization to limit the returned records, this has funny results occasionally:

Person.with_permissions_to(:index).paginate :per_page => 20, :page => page,
              :conditions => ["first_name LIKE ? or last_name LIKE ?", '%'+q + '%', '%'+q + '%' ],
              :order => 'last_name, first_name'

if I remove the with_perissions_to(:index) it works fine.

The problem is that the pager links do not always show the right number of pages. Depending on the :order fields, I have seen the pager links disappear (which seems to indicate one page) and the items were not sorted; (:order => 'last_name') or if I do it as above, it originally shows 3 pages, but when I click next, it goes to page 2 and shows that it is the last page. I can put page=3 in the url and see the data though.

The truly weird part, is with the data I have, I can only replicate it on the search 'nelson'.

As a workaround, I used proxy_options as described elsewhere:

      options = {}
  # determining options needed for ordering etc.
  #
  # Getting the options hash from the named scope via proxy_options:
  options.merge! Person.with_permissions_to(:index).proxy_options
  options.merge! :per_page => 20, :page => params[:page],
              :conditions => ["first_name LIKE ? or last_name LIKE ?", '%'+params[:q] + '%', '%'+params[:q] + '%' ],
              :order => 'last_name, first_name'
  @people = Person.paginate options

missing method "include_method?" for array

Seems like the current version is trying to find out whether ActionView::Base does include the "will_paginate" method.
I hope it's just the typo and you meant to use include? instead of include_method?
Line 20 in will_paginate.rb
I am currently running ruby 1.8.7 with rails 2.3.2 and the latest master of this plugin

Website Submodule is inaccessible

After forking mislav/will_paginate,

$ git clone [email protected]:[me]/will_paginate.git
$ git checkout rails3
$ git submodule init
  Submodule 'website' ([email protected]:mislav/will_paginate.git) registered for path 'website'
$ git submodule update
  Initialized empty Git repository in /home/me/code/will_paginate/website/.git/
  ERROR: Permission to mislav/will_paginate denied to [me].
  fatal: The remote end hung up unexpectedly
  Clone of '[email protected]:mislav/will_paginate.git' into submodule path 'website' failed

Unable to install with bundler from git repo

My Gemfile contains

gem "will_paginate", :git => "git://github.com/mislav/will_paginate.git", :branch => "rails3"

bundle install

/opt/local/lib/ruby/gems/1.8/gems/bundler-0.9.7/lib/bundler/source.rb:242:in `specs': /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- /Users/zven/.bundle/ruby/1.8/cache/bundler/git/will_paginate-6ad077380835d8b425f1d46ebc3ada46214e7bbb/lib/will_paginate/version (LoadError)

Complete useless trace available in this gist

Implicit per_page not working in Rails 3.0 beta3

I'm trying will_paginate on RoR 3.0beta3. Given this model:

class News < ActiveRecord::Base
  cattr_reader :per_page
  @@per_page = 10
end

In my model, if I do this way:

@news = News.where("visibile = ? AND inizio <= ? AND fine >= ?", true,
  Date.today, Date.today).order("created_at DESC").paginate(:page => page)

I get 30 items. If I do this way:

@news = News.where("visibile = ? AND inizio <= ? AND fine >= ?", true,
  Date.today, Date.today).order("created_at DESC").
  paginate(:page => page, :per_page => News.per_page)

I correctly get 10 items.

This means that I apparently found a bug: the per_page method (or attribute is ignored at the the end of the Rails 3 AR chain.

Fails load will_paginate on Rails3

Will_paginate load fail in Rails3, seems it's a name space issue:

=> Booting WEBrick
=> Rails 3.0.0.beta1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:440:in `load_missing_constant': WillPaginate::Finders is not missing constant Base! (ArgumentError)
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:153:in `block in const_missing'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:151:in `each'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/dependencies.rb:151:in `const_missing'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/will_paginate-6ad077380835d8b425f1d46ebc3ada46214e7bbb-rails3/lib/will_paginate/finders/active_record.rb:31:in `enable!'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/will_paginate-6ad077380835d8b425f1d46ebc3ada46214e7bbb-rails3/lib/will_paginate/railtie.rb:11:in `block in <class:Railtie>'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:25:in `run'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:54:in `each'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/application.rb:69:in `initialize!'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/application.rb:43:in `method_missing'
from /Users/kaichen/Workspace/will_paginate_example/config/environment.rb:5:in `<top (required)>'
from config.ru:3:in `require'
from config.ru:3:in `block in <main>'
from /Users/kaichen/Workspace/will_paginate_example/vendor/gems/rack-1.1.0/lib/rack/builder.rb:46:in `instance_eval'
from /Users/kaichen/Workspace/will_paginate_example/vendor/gems/rack-1.1.0/lib/rack/builder.rb:46:in `initialize'
from config.ru:1:in `new'
from config.ru:1:in `<main>'
from /Users/kaichen/Workspace/will_paginate_example/vendor/gems/rack-1.1.0/lib/rack/builder.rb:35:in `eval'
from /Users/kaichen/Workspace/will_paginate_example/vendor/gems/rack-1.1.0/lib/rack/builder.rb:35:in `parse_file'
from /Users/kaichen/Workspace/will_paginate_example/vendor/gems/rack-1.1.0/lib/rack/server.rb:113:in `app'
from /Users/kaichen/Workspace/will_paginate_example/vendor/gems/rack-1.1.0/lib/rack/server.rb:189:in `wrapped_app'
from /Users/kaichen/Workspace/will_paginate_example/vendor/gems/rack-1.1.0/lib/rack/server.rb:155:in `start'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/commands/server.rb:57:in `start'
from /Users/kaichen/Workspace/will_paginate_example/vendor/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/commands.rb:42:in `<top (required)>'
from ./script/rails:9:in `require'
from ./script/rails:9:in `<main>'

It happens under REE and 1.9. Rails version is higher than 3.0.0.beta1.

I forked and fixed it here: http://github.com/kaichen/will_paginate

entry name underscores in page_entries_info

The default entry_name logic works better if you change the sub() call to gsub(). Then it handles classes with multiple underscores gracefully.

entry_name = options[:entry_name] ||
  (collection.empty?? 'entry' : collection.first.class.name.underscore.gsub('_', ' '))

paginated_section HTML escaping bug in Rails 3

Using rails 3.0.0.beta3 and using the head of will_paginate's rails 3 branch

The method paginated_section possibly outputs escapes the HTML output instead of using the raw output

Paginating one page objects yields only the raw HTML of the request.

If multi-page objects are used, they render just fine however (output raw non-escaped HTML)...

For example:

<%= paginated_section @artists do %>
  <%= render @artists %>
<% end %>

will produce escaped HTML if @artists has one page and raw HTML if it has more than one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.