简体   繁体   English

在轨道上使用kaminari进行无休止的滚动,如何渲染?

[英]Endless scrolling with kaminari in rails, how to render?

I am following this tutorial: https://github.com/amatsuda/kaminari/wiki/How-To:-Create-Infinite-Scrolling-with-jQuery 我正在关注本教程: https : //github.com/amatsuda/kaminari/wiki/操作方法-Create-Infinite-Scrolling-with-jQuery

So far everything works great, but I am stuck at the last part of the tutorial. 到目前为止,一切都很好,但是我被困在本教程的最后一部分。

The content in my show.html.haml gets rendered like this: 我的show.html.haml中的内容按以下方式呈现:

- @search_results.each do |search_result|
  =render 'search_result', :search_result=>search_result

The problem is that I have no idea how to translate that to show.js.erb , currently I have (mimicked from the tutorial) 问题是我不知道如何将其转换为show.js.erb (目前已被本教程模仿)

$(".offers").append("<%= escape_javascript(render(@search_results)) %>");

but that throws errors. 但这会引发错误。 (undefined method `model_name' for Hash:Class) (Hash:Class的未定义方法“ model_name”)

in my controller, search results is defined as: 在我的控制器中,搜索结果定义为:

@search_results =  Kaminari.paginate_array(all_search_results).page(params[:page]).per(6)

all_search_results is an array that gets filled with stuff from another model. all_search_results是一个数组,其中填充了其他模型中的内容。

<%= @search_results.map {|search_result| render('search_result.html', :search_result => search_result)}.to_json.html_safe %>

做到了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM