提问人:Sean Magyar 提问时间:5/21/2016 更新时间:6/3/2016 访问量:1047
不同部分的导轨will_paginate
rails will_paginate with different partials
问:
我对通知模型有一些新的操作,事情开始变得混乱,所以我从 with 重构为以下结构。<% = render @other_notifications %>
notifcations/_notification.html.erb
我的问题如下。页面很好地呈现了所有内容,但分页无法正常工作。因此,如果我具有下面的结构并且不删除,则页面将加载新的操作部分,并且分页对象将加载 .如果我删除,那么页面仍然会加载新的部分,但分页不起作用。我应该如何更改分页以使其工作?_notification.html.erb
_notification.html.erb
_notification.html.erb
notifications_controller.rb
def other_notifications
@other_notifications = current_user.notifications.not_chat.order(created_at: :desc).includes(:sender_profile).
paginate(page: params[:page], per_page: Notification.pagination_per_page)
current_user.reset_new_other_notifications
respond_to do |format|
format.html
format.js
end
end
other_notifications.html.erb
<div class = "other-notifications-index">
<% @other_notifications.each do |notification| %>
<% if lookup_context.template_exists?(notification.action, "notifications/actions", true) %>
<%= render partial: "notifications/actions/#{notification.action}", locals: { notification: notification } %>
<% end %>
<% end %>
</div>
<div id="infinite-othernotification-scrolling">
<%= will_paginate @other_notifications %>
</div>
other_notifications.js.erb
$('.other-notifications-index').append('<%= j render @other_notifications %>');
<% if @other_notifications.next_page %>
$('.pagination').replaceWith('<%= j will_paginate @other_notifications %>');
<% else %>
$(window).off('scroll');
$('.pagination').remove();
$('.no-more').delay(1000).fadeIn(1500);
<% end %>
答:
0赞
Sean Magyar
6/3/2016
#1
我是这样解决的。所以 will paginate 将查找 partial,这将始终使用以下代码找到,并且 partial 将调用其余的 partials。_notification
_notification
other_notifications.html.erb
<%= render @other_notifications %>
<%= will_paginate @other_notifications %>
_notification.html.erb
<% if lookup_context.template_exists?(notification.action, "notifications/actions", true) %>
<%= render partial: "notifications/actions/#{notification.action}", locals: { notification: notification } %>
<% end %>
评论