I am trying to do a "Twitter like" pagination with a "More" button to load results with Kaminari.
I found this question here
But I can't figure out how to make it works and if it's a good approach.
Thanks in advance
I am trying to do a "Twitter like" pagination with a "More" button to load results with Kaminari.
I found this question here
But I can't figure out how to make it works and if it's a good approach.
Thanks in advance
Do you mean you need a "more" button? How about creating a helper like this?
# usage:
# link_to_next_page(@items)
# link_to_next_page(@items, :remote => true) # Ajax
def link_to_next_page(scope, name, options = {}, &block)
param_name = options.delete(:param_name) || Kaminari.config.param_name
link_to_unless scope.last_page?, name, {param_name => (scope.current_page + 1)}, options.merge(:rel => 'next') do
block.call if block
end
end
I'm ready to include this kind of helper methods to the gem if you find it useful, so please let me know what you think. Thanks!
link_to_next_page(@items, :remote => true)
or link_to_next_page(@items, :remote => false)
, so it's the same, after click on the link I will get to URL page parameter. What I am doing bad? –
Landre Keep in mind that link_to_next_page(@items, :remote => true)
won't work correctly out of the box. Since it has no way to determine the current page after an Ajax request, the link needs to be replaced after new items are fetched. Using unobtrusive javascript, this would something look like this:
# app/views/items/index.js.erb
$(".items").append("<%= escape_javascript(render(@items)) %>");
$(".more_link").replaceWith("<%= escape_javascript(
link_to_next_page @items, 'View more',
:remote => true,
:id => :view_more) %>");
If this doesn't make sense, take a look at the Unobtrusive Javascript screencast at Railscasts.
© 2022 - 2024 — McMap. All rights reserved.