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

Problems with kaminari #72

Closed
lfv89 opened this issue Apr 7, 2014 · 6 comments
Closed

Problems with kaminari #72

lfv89 opened this issue Apr 7, 2014 · 6 comments

Comments

@lfv89
Copy link

lfv89 commented Apr 7, 2014

This works:

Article.search(query: 'Brazil').page(1).records

But this...

Article.search(query: 'Brazil').page(1).records.current_page

Throw this error:

Hash can't be coerced into Fixnum

Because of this error I can't make the kaminari pagination helper to work on my views, am I missing something?

ruby 2.0
rails 3.2
kaminari 0.14.1
kaminari-bootstrap 0.1.3
elasticsearch-rails 0.1.0
elasticsearch-model 0.1.0

@karmi
Copy link
Contributor

karmi commented Apr 7, 2014

That's quite weird, see the integration test at https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/test/integration/active_record_pagination_test.rb#L42

Are you loading Kaminari before the elasticsearch-model gem or configuring it?

@lfv89
Copy link
Author

lfv89 commented Apr 7, 2014

Hi Karmi, thanks for your response.

Yes, actually I'm both loading kaminari before the elasticsearch-model gem and also configuring it as you said in a related issue (sorry, forget the issue number). I'm gonna take a look at this integration test in a few hours than I reply here. And before I forget, I'm not using Activerecord, I'm using Mongoid!

@lfv89
Copy link
Author

lfv89 commented Apr 10, 2014

@karmi I just found the error. In a given context my search definition had a size: {}. So, the method limit_value from elasticsearch-model/lib/elasticsearch/model/response/pagination.rb was returning an empty hash, which broke the kaminari calculations. I thought of sending a PR to ensure that limit_value method will always return a number, but then I thought that the error was only my fault, so I changed my mind. What do you think?

@karmi
Copy link
Contributor

karmi commented Apr 10, 2014

Yeah, I think think people should just pass a number to size, I wouldn't hand-hold them :)

@benben
Copy link

benben commented Apr 10, 2014

btw this is also working for me with the patch from #42

@lfv89
Copy link
Author

lfv89 commented Apr 10, 2014

Good to know @benben. It was my mistake, I'm closing this issue!

@lfv89 lfv89 closed this as completed Apr 10, 2014
karmi pushed a commit that referenced this issue Apr 16, 2014
Previously:

  When klass.default_per_page is 25,

  response.limit(35).page(3)
  => :size is back to 25, :from is 25 * 2

  response.page(3).limit(35)
  => :size is 35, but :from is 25 * 2

After this patch:

  response.limit(35).page(3)
  => :size is 35, :from is 35 * 2

  response.page(3).limit(35)
  => :size is 35, :from is 35 * 2

Closes #42

Related: #72, #55
karmi pushed a commit that referenced this issue Apr 16, 2014
Previously:

  When klass.default_per_page is 25,

  response.limit(35).page(3)
  => :size is back to 25, :from is 25 * 2

  response.page(3).limit(35)
  => :size is 35, but :from is 25 * 2

After this patch:

  response.limit(35).page(3)
  => :size is 35, :from is 35 * 2

  response.page(3).limit(35)
  => :size is 35, :from is 35 * 2

Closes #42

Related: #72, #55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants