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

Pagination links not showing on first page #460

Open
cahitceren opened this issue Dec 11, 2015 · 3 comments
Open

Pagination links not showing on first page #460

cahitceren opened this issue Dec 11, 2015 · 3 comments

Comments

@cahitceren
Copy link

Hi there,

I have a problem with pagination display.

I cant display pagination display on first page.

For example: http://www.etkinlikplus.com/static/home
on this link there isnt pagination links.

But on second page: http://www.etkinlikplus.com/static/home?page=2
on this link pagination links display.

I look all over internet but there is no solution even I dont have any error on heroku logs.

I want to add that I'm facing this problem only on remote(heroku). On local, pagination links are displaying correctly.

Problem still continue.

@cahitceren
Copy link
Author

I fınd another thing.

When I remove order query from object pagination display on first page. But when I add order query it disappers.

Edit: I remove order from controller and added default scope with order but problem still continue.

PS: order that I add is
default_scope{order('schedules.starting_at ASC')}

update:
I find another thing.

There is two field in my schedules table one is starting_at(time), the other is occuring_on(date).

When I order by occuring_on pagination displays.

But when I order by starting_at pagination disappear on first page.

interesting update:
When I change sort order ASC to DESC, pagination links displays.

But for asc sort, problem still continue.

@louisshepherd
Copy link

For anyone running into this, I had a similar problem when sorting on an attribute translated by the Globalize Gem.

The problem was for me that after applying the .order() clause, the active_record .limit() method was returning a wrong count because of .limit() using DISTINCT somewhere in the generated SQL.
When items with multiple translations where included the the .limit() method would return less items then specified.

So a call to Item.with_translations.order('item_translations.sort_string ASC').limit(4).count would return 3 objects, because one of them had two translations where one was filtered out by the DISTINCT clause.

This caused WillPaginate to think it had less items then the per_page limit allowed and than hide the pagination links

The solution for my problem here was to join the specific translations only to guarantee a correct count for WillPaginate.

Item.with_translations.joins(:translations).where('item_translations.locale = ?', I18n.locale).order('item_translations.sort_string ASC').limit(4).count == 4

@shobee
Copy link

shobee commented Jun 30, 2017

@caccac Today I ran into the same problem. DESC sorting on a string column works fine but changing it to ASC let the pagination links disappear. Did you found a solution on this?

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