带有will_paginate的无尽页面无法与部分页面一起使用 [英] Endless page with will_paginate not working with partial
问题描述
我一直在无休止的页面上关注 railscast ,以前曾经做过对于will_paginate也是一样,但是我遇到了错误,但是我尝试在我的特定情况下实现它.从阅读Chrome中的开发人员工具可以得知,will_paginate gem可以完美地工作,jQuery对dom的jQuery调用也是如此.问题在于返回的内容-Rails不喜欢它.这是一些代码:
I've been following the railscast on endless page and had previously done the same for will_paginate, but I'm getting errors however I try to implement it in my specific situation. The will_paginate gems works perfectly, as does the jQuery call to the dom as far as I can tell from reading the developer tools in Chrome. The issue is with what is being returned - rails doesn't like it. Here's some code:
在videos.js.coffee
中:
jQuery ->
if $('.pagination').length
$(window).scroll ->
url = $('.pagination .next_page').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
$('.pagination').text("Fetching more videos...")
$.getScript(url)
$(window).scroll()
在我的views/users/index.js.erb
$('.carousel').append(' <%= j render(@recently_added_video) %>');
<% if @recently_added_video .next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@recently_added_video) %>');
<% else %>
$('.pagination').remove();
<% end %>
在我的共享部分中,该部分由users/index.erb.html
In my shared partial, which is being rendered by users/index.erb.html
<div class="carousel" %>
<ul class="jcarousel-skin-recent">
<% @recently_added_video.each do |v| %>
<li><%= link_to image_tag(v.video_thumb(), width: 300), v %></li>
<% end %>
</ul>
</div>
<%= will_paginate @recently_added_video %>
这使我的开发日志出现以下错误:
This gives me the following error from my development log:
Completed 500 Internal Server Error in 15ms
ActionView::Template::Error (Missing partial videos/video with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}.
因此,我然后尝试使用与users/index.js.erb
文件相同的代码创建views/videos/_video.js.erb
部分,但是随后出现以下错误:
So I then tried creating a views/videos/_video.js.erb
partial with the same code as the users/index.js.erb
file, but it then gives me the following error:
Rendered shared/_recentlyadded.html.erb (853.8ms)
Rendered users/index.html.erb within layouts/application (1741.4ms)
Rendered layouts/_header.html.erb (2.6ms)
Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 1813ms (Views: 1801.0ms | ActiveRecord: 8.5ms | Sphinx: 0.0ms)
Illegal instruction: 4
并且您可以看到,它实际上也没有渲染_video
部分.
and as you can see, it hasn't actually rendered the _video
partial either.
在相关性方面,我要调用的实例变量@recently_added_video
在application_controller
中定义,并且可以与partial和will_paginate
正常工作.
In case it's of relevance, the instance variable @recently_added_video
I'm trying to call is defined in the application_controller
and works fine with the partial and will_paginate
.
任何人都可以帮助您找出问题所在吗?很迷惑!谢谢...
Can anyone help figure out what's going wrong? Very confused! Thanks...
推荐答案
没关系-我想通了.
问题出在这行
$('.carousel').append( ' <%= j render(@recently_added_video) %>' );
在users/index.js.erb文件中.
in the users/index.js.erb file.
我一直在跟踪轨道,但是Ryan Bates设置了他的实例变量来呈现部分内容,因此他的代码可以工作,但是由于@recently_added_video不是局部的并且不会呈现内容,因此它返回了500错误因为没有部分可以找到.
I was following the railscast, but Ryan Bates has his instance variable set up to render a partial, so his code works, but because @recently_added_video isn't a partial and won't render one, it was returning the 500 error because there was no partial to find.
我需要做的实际上是渲染这样的局部图像:
What I needed to do was actually render a partial like this:
$('.jcarousel-skin-recent').append(' <%= j render ('shared/recentlyadded') %>');
希望可以帮助其他追随轨道的人,并像我一样遇到问题.
Hope that helps anyone else who follows the railscast and has issues like I did.
这篇关于带有will_paginate的无尽页面无法与部分页面一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!