0

Я слежу за # 114 Endless Scrolling Railscast (http://railscasts.com/episodes/114-endless-page-revised), и у меня есть бесконечная функция прокрутки для работы с Kaminari.Бесконечная прокрутка перестает работать после генерации темы

Однако, когда я создал тему для Foundation, функция бесконечной прокрутки перестает работать, а вместо нее отображается разбиение на страницы.

products.js.coffee

jQuery -> 
    if $('.pagination').length 
     $(window).scroll -> 
       url = $('.pagination .next a').attr('href') 
       if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50 
         $('.pagination').text('Fetching more products...') 
         $.getScript(url) 
$(window).scroll() 

index.html.erb

<div id="products"> 
    <%= render "products" %> 
    </div> 

    <div class="row"> 
    <div class="small-12 columns"> 
     <%= paginate @products, window: 2 %> 
    </div> 
    </div> 

index.js.erb

$('#products').append('<%= j render "products" %>'); 
<% if @ products %> 
    $('.pagination').replaceWith('<%= j paginate(@products) %>'); 
<% else %> 
    $('.pagination').remove(); 
<% end %> 
<% sleep 1 %> 

Для создания фонда Views https://github.com/amatsuda/kaminari_themes/tree/master/foundation

rails g kaminari:views foundation 

Почему бы сгенерированный вид остановить бесконечный скроллинг от работы? Благодарю.

Редактировать

Я использую фонд 5 и камень Kaminari, не will_paginate.

Gemfile

source 'https://rubygems.org' 
ruby '2.1.3' 


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.1.6' 
# Use postgresql as the database for Active Record 
gem 'pg' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 4.0.3' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .js.coffee assets and views 
gem 'coffee-rails', '~> 4.0.0' 
# See https://github.com/sstephenson/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0',   group: :doc 

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
gem 'spring',  group: :development 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano-rails', group: :development 

# Use debugger 
# gem 'debugger', group: [:development, :test] 

gem 'friendly_id', '~> 5.0.0' 
gem 'pg_search' 
gem 'actionpack-page_caching' 
gem 'rails-observers' 

gem 'foundation-rails' 
gem 'rails_12factor', group: :production 
gem 'jquery-turbolinks' 
gem "font-awesome-rails" 
gem 'kaminari' 

ответ

0

мне удалось выяснить, что случилось.

Генерируя мнения Foundation, мне нужно изменить, чтобы products.js.coffee:

jQuery -> 
    if $('.pagination').length 
      $(window).scroll -> 
        url = $('ul.pagination a[rel=next]').attr('href') 
        if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50 
          $('.pagination').text('Fetching more products...') 
          $.getScript(url) 
    $(window).scroll() 

Обратите внимание на изменения в URL.

Смежные вопросы