我正在尝试使用will_paginate和coffee进行无限滚动,在我编写代码后,它给了我这个错误?

我使用ATOM ATOM作为我的IDE ....... <<<<<

Showing C:/Users/more/Desktop/railsapp/app/views/layouts/application.html.erb where line #6 raised:

    SyntaxError: [stdin]:7:1: unexpected indentation


我的posts.coffee

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
  if $('#infinite-scrolling').size() > 0
    $(window).on 'scroll', ->
      more_posts_url = $('.pagination .next_page a').attr('href')
        if more_posts_url && $(window).scrollTop() > $(document).height() - $(window).height() - 60
            $('.pagination').html('<p> loading <p>')
            $.getScript more_posts_url
        return
      return

最佳答案

在more_posts_url变量之后,您还有一个缩进块:

if $('#infinite-scrolling').size() > 0
  $(window).on 'scroll', ->
    more_posts_url = $('.pagination .next_page a').attr('href')
    if more_posts_url && $(window).scrollTop() > $(document).height() - $(window).height() - 60
      $('.pagination').html('<p> loading <p>')
      $.getScript more_posts_url
    return
  return

10-04 21:42
查看更多