Comments (13)
It would be nice to set the name of the parameter when there is more than one collection being paginated; otherwise, it would conflict. For example, you could have pagination for customers and employees on two tabs in the same page. When the page is changed for one, since :page is used for both, it is indistinguishable which collections page should be changed.
from kaminari.
Here's a naive patch that allows you to localize links by adding the translation string views.pagination.page to your locale.
diff --git i/lib/kaminari/helpers/tags.rb w/lib/kaminari/helpers/tags.rb
index 6fdb13a..ce4753c 100644
--- i/lib/kaminari/helpers/tags.rb
+++ w/lib/kaminari/helpers/tags.rb
@@ -47,7 +47,8 @@ module Kaminari
end
def page_url_for(page)
- @template.url_for @template.params.merge(:page => (page <= 1 ? nil : pa
+ page_param = I18n.t('views.pagination.page').to_sym
+ @template.url_for @template.params.merge(page_param => (page <= 1 ? nil
end
end
EDIT: You'd also have to do the same for the :page at around lines 97 and 170 in the same file
The problem with this patch is that you'll have to write something ugly in your controller.
@users = User.order(:name).page params[I18n.t('views.pagination.page').to_sym]
Writing that over and over will probably make you want something like this:
module Kaminari
def self.page_param
I18n.t('views.pagination.page').to_sym
end
end
This will work, but I'm not very happy with the API.
from kaminari.
Buggy, ugly, possibly incomplete implementation of the above "fix"
https://github.com/l15n/kaminari/tree/i18n-param
Probably doesn't work properly. But it might...
I have a feeling that the using the i18n API here is a bad idea. Should parameter names really change for each language? I'm uncomfortable with the idea of parameter names changing based on the users locale.
Perhaps a good compromise would be to allow the name for the page parameter to be set on a per-application basis rather than a per-locale basis.
from kaminari.
l15n
Thanks for the patch!
But seeing blatyo's comment and some comments on the Railscasts' episode http://railscasts.com/episodes/254-pagination-with-kaminari
I guess it's better to simply add a new option for the parameter name to the paginate helper.
I think I finished adding the option, so it will be enabled since 0.10.2.
from kaminari.
I would prefer an API that would allow me to set the parameter name on the call to paginate. For example:
<%= paginate @users, :page_param => I18n.t('views.pagination.page').to_sym %>
Also, I think it would be a reasonable convention to name the parameter after the plural name of the type of records being paginated. For example, paginate @users
would by default set :param_name => :users_page
. This would allow for multiple paginations to be on the same page without having to set :param_name
every time.
Finally, the default place to look for a localization could be views.pagination.<param_name>
where param_name would be something like users_page
. Then the logic for deciding what to use as the parameter would be something like this inside page_url_for
:
page_param = I18n.t("views.pagination.#{page_param}").try(:to_sym) || page_param
Unfortunately this doesn't fix the problems you noted with the patch you proposed. However, I would discourage a single page parameter, because it isn't flexible for multiple paginations on the same page.
EDIT: Wrote this before seeing the two comments above this.
from kaminari.
Oops. Lots of comments! So, this is my commit.
amatsuda@5826382
Are you OK with this?
from kaminari.
@amatsuda, I can certainly meet my use case with this solution.
Do you have any comment about changing the default param_name
? For example:
def paginate(scope, options = {}, &block)
Kaminari::Helpers::PaginationRenderer.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => inflect_param_name(scope), :remote => false)
end
private
def inflect_param_name(scope)
scope_type = scope.first.try(:class).try(:name).try(:downcase)
scope_type ? :"#{scope_type}_page" : :page
end
from kaminari.
@amatsuda thanks for the quick work! I tested the branch and at first it appears to work, but after going to a page, the links for the pagination get an additional parameter. Say the current page is 3, param_name is 'pagina', the link to page 4 will be: ?page=3&pagina=4
from kaminari.
@IvanVr Thank you for testing! But that doesn't happen for me...
Maybe I'm missing something, but anyway let me push this to master and ship another gem because this change won't cause any regression to the existing apps.
from kaminari.
@blatyo Well, I tested that but the URL looks a bit redundant, so I don't like this to be the default.
http://example.com/books?book_page=3
from kaminari.
I'm sorry this ticket are going to be automatically closed as I push my commit to master.
Feel free to reopen or create another ticket if you want to keep the discussion open.
Thanks!
from kaminari.
closed by f9f529f add :param_name option to the helper
example: <%= paginate @users, :param_name => :pagina %>
from kaminari.
- I have two tabs in index-page , when i click on first tab it show 12 item and load more using infinite-scroll pagination.
- I have used like this in view,
<%= paginate @articles %>
and
<%= paginate @most_popular_articles, :remote => true, :param_name => 'pagina' %>
But, /?page=3&pagina=1
. like, page is updating while scrolling; pagina is not updated.
Parameters: {"page"=>"4", "pagina"=>"1"}
. please fix the issue.
from kaminari.
Related Issues (20)
- rails g kaminari:views bulma does not work on Ruby 3 HOT 2
- enter custom page number HOT 3
- rails g kaminari:views doesn't generate anything HOT 12
- Hi HOT 1
- undefined local variable or method `paginator' for _page.html.erb:22 partial HOT 2
- Undefined method `without_count' HOT 2
- Update wiki link in GitHub "About" section HOT 1
- issue on method_missing due to separation of positional and keyword arguments in Ruby 3
- Is it possible to add 'data-turbo-action' to the paginate helper? HOT 4
- How to use "Creating Friendly URLs and Caching" in "member do" ?
- With the update from i18n to v1.11.0 `:zero` in not longer supported as key
- Problem Monkey Patching Rails 7.0
- render error for js.erb
- when large table query, use total_count and total_pages slow
- paginate view helper is failing with includes HOT 3
- Updating content_for blocks
- `link_to_first_page` / `link_to_last_page` ?
- inconsistent results in case of LEFT OUTER JOIN, GROUP BY and HAVING HOT 2
- Array doesn't get paginated when total count is passed in HOT 1
- Ambiguous column "id" when PG COUNT is used with certain joins HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaminari.