Javascript 卡米纳里的无限卷轴';我什么也不做
作为指导,我根据我的具体情况定制了代码,但我的应用程序中没有发生任何变化。kaminari的分页效果很好,但是完全没有无限滚动。让我的部分添加额外的抽象层真的让我困惑 micropost_控制器.rbJavascript 卡米纳里的无限卷轴';我什么也不做,javascript,ruby-on-rails-4,infinite-scroll,kaminari,Javascript,Ruby On Rails 4,Infinite Scroll,Kaminari,作为指导,我根据我的具体情况定制了代码,但我的应用程序中没有发生任何变化。kaminari的分页效果很好,但是完全没有无限滚动。让我的部分添加额外的抽象层真的让我困惑 micropost_控制器.rb def index @micropost = current_user.microposts.build @microposts = Micropost.order(:created_at).page(params[:page]) end 查看micropost index.html.
def index
@micropost = current_user.microposts.build
@microposts = Micropost.order(:created_at).page(params[:page])
end
查看micropost index.html.erb
<%= render 'shared/public_feed' %>
更新代码
我改变了一些类/ID,试图更好地适应教程,但仍然没有运气。另外,根据我的rails控制台,没有呈现index.js.erb
Rendered shared/_feed_item.html.erb (595.7ms)
(1.4ms) SELECT COUNT(*) FROM "microposts"
Rendered shared/_public_feed.html.erb (1140.4ms)
Rendered microposts/index.html.erb within layouts/application (1210.7ms)
Rendered layouts/_shim.html.erb (0.1ms)
Rendered layouts/_header.html.erb (1.1ms)
Rendered layouts/_footer.html.erb (0.3ms)
但是,当我导航到http://localhost:3000/microposts.js
我的订阅源项目部分出现此错误
undefined local variable or method `feed_item' for #<#<Class:0xb998f134>:0xb9cd7198>
未定义的局部变量或方法“feed\u item”#
但是,如果我在index.js.erb文件中将'shared/feed_item'
替换为@microsopsts
,我会得到一堆纯文本,因此我假设它在javascript中没有遇到任何错误
更新2:根据这个github问题,index.js.erb甚至没有被使用。。现在我真的很困惑
更新3我创建了一个新应用程序,并严格按照说明操作,但删除了index.js.erb文件,演示应用程序仍能正常运行。所以我遇到的问题一定是在我的咖啡脚本中,但是当我运行它时,我的javascript日志中没有任何错误
更新4因此,在从指南安装演示应用程序后,我将
和
元素更改为
元素,无限滚动停止工作。为了让它加载工作,我必须将窗口调整得更小,然后向下滚动以触发事件。还不确定这如何适用于我的特定问题。当使用kaminari的分页主题,特别是twitter引导主题时,它会将nav标记更改为div标记。为了让代码正常工作,我必须将coffeescrip文件中的nav.pagination选择器更改为div.pagination
$("#posts").append("<ol class='page'><%= escape_javascript(render('shared/feed_item')) %></ol>");
$(document).ready ->
$("#microposts .page").infinitescroll
navSelector: "nav.pagination" # selector for the paged navigation (it will be hidden)
nextSelector: "nav.pagination a[rel=next]" # selector for the NEXT link (to page 2)
itemSelector: "#posts div.post" # selector for all items you'll retrieve
Rendered shared/_feed_item.html.erb (595.7ms)
(1.4ms) SELECT COUNT(*) FROM "microposts"
Rendered shared/_public_feed.html.erb (1140.4ms)
Rendered microposts/index.html.erb within layouts/application (1210.7ms)
Rendered layouts/_shim.html.erb (0.1ms)
Rendered layouts/_header.html.erb (1.1ms)
Rendered layouts/_footer.html.erb (0.3ms)
undefined local variable or method `feed_item' for #<#<Class:0xb998f134>:0xb9cd7198>