Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentError: comparison of Fixnum with String failed #849

Closed
rafaelgonzalez opened this issue Jan 13, 2017 · 2 comments
Closed

ArgumentError: comparison of Fixnum with String failed #849

rafaelgonzalez opened this issue Jan 13, 2017 · 2 comments
Labels
Milestone

Comments

@rafaelgonzalez
Copy link

rafaelgonzalez commented Jan 13, 2017

Description

This happens when calling page_entries_info with a collection created with .page().per() by passing a String to .per().

If the collection was created by passing an integer to .per() it all works fine.

Solution

I have found that changing this line to this fixes the issue:

@_per = num.to_i

Also, as a temporary solution I can cast the argument passed to .per() to an integer.

Steps to replicate

This fails:

include Kaminari::Helpers::HelperMethods
collection = User.page(1).per("5") # passing a String to .per()
page_entries_info(collection) # raises: ArgumentError: comparison of Fixnum with String failed

This works fine:

include Kaminari::Helpers::HelperMethods
collection = User.page(1).per(5) # passing a Fixnum to .per()
page_entries_info(collection) # this will trigger an error because translation module is not included, but the method works as expected

Stack trace

ArgumentError: comparison of Fixnum with String failed
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/kaminari-activerecord-1.0.0/lib/kaminari/activerecord/active_record_relation_methods.rb:25:in `<'
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/kaminari-activerecord-1.0.0/lib/kaminari/activerecord/active_record_relation_methods.rb:25:in `total_count'
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/kaminari-core-1.0.0/lib/kaminari/models/page_scope_methods.rb:36:in `total_pages'
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/kaminari-core-1.0.0/lib/kaminari/helpers/helper_methods.rb:107:in `page_entries_info'
	from (irb):5
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/railties-4.2.7.1/lib/rails/commands/console.rb:110:in `start'
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/railties-4.2.7.1/lib/rails/commands/console.rb:9:in `start'
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:68:in `console'
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
	from /Users/rafaelgonzalez/.rvm/gems/ruby-2.3.3/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>'
	from bin/rails:8:in `require'
	from bin/rails:8:in `<main>'
@yuki24 yuki24 added the Bug label Jan 13, 2017
@yuki24 yuki24 added this to the 1.0.1 milestone Jan 13, 2017
@yuki24 yuki24 closed this as completed in 01ec38a Jan 13, 2017
@yuki24
Copy link
Member

yuki24 commented Jan 13, 2017

Thanks for reporting! I just fixed this bug. We are planning on releasing a bugfix version in the coming days. Thank you again for your contribution!

@rafaelgonzalez
Copy link
Author

rafaelgonzalez commented Jan 13, 2017

Ah cool, thanks! Sure thing, I'll be sure to watch this space 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants