I've noticed how Akira Matsuda have added helper in Kaminari gem and made ti a lot simple for us to use Load more button.
I've read the document and figured simply adding
<%= link_to_next_page @items, 'Next Page' %>
should make the ajax load button work, but id didn't. So I googled few other articles for some help and I wrote few extra things...
Here are what I have right now.
I have these files
root.html.slim
ul#works
= render :partial => "works"
work.html.slim
- @works.each do | work |
= link_to work
li
span.thumb
= work_image_of work
h4 = link_to work.title, work, thumb:true
p.pull-left
small
= work.collaborators.count.to_s
| collaborators
= link_to_next_page @works, 'Next Page', id: 'view_more'
index.controller
def root
@works = Work.page(params[:page]).per(9)
render :layout => 'application'
end
also added in application.js
$('#works').append("<%= escape_javascript(render 'works', object: @works) %>");
$("#view_more").replaceWith("<%= escape_javascript(
link_to_next_page(@works, 'more', remote: true, id: 'view_more')
) %>");
and this in action helper,
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 have jquery included in my js files. What am I missing? Please help me out!
Thank you for your time!!