0

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
        |&nbsp;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!!

Davide Pastore
  • 8,678
  • 10
  • 39
  • 53
Hirohito Yamada
  • 387
  • 1
  • 4
  • 17
  • Have you taken a look at: https://github.com/amatsuda/kaminari/wiki/How-To:-Create-Infinite-Scrolling-with-jQuery – apod Feb 04 '16 at 13:57
  • No, I have not. I'll take a look. – Hirohito Yamada Feb 04 '16 at 14:45
  • It looks to me like what you're missing is the equivalent of the very last coffeescript on that page. Basically, you need a javascript that runs when the user scrolls to bottom of the page. – apod Feb 04 '16 at 14:47
  • thanks for the tip, but I dont want the app to automatically load more post when users scroll to bottom of the page. I want the button to trigger the action. Is coffee script still the problem that needs to be solved? – Hirohito Yamada Feb 04 '16 at 15:56

0 Answers0