【问题标题】:Rails: Pagination in Bootstrap ModalRails:引导模式中的分页
【发布时间】:2017-11-05 20:32:55
【问题描述】:

我有一份产品清单。当用户点击产品时,会出现一个包含所有购买优惠的模式。如何将此购买优惠结果分页到模态中? 最终目标是在模态中实现无限滚动(如 Twitter)。

关系:

  1. Order has_many :buy_orders
  2. BuyOrder belongs_to :product

Products.html.erb

<% @products.each do |product| %>
<button type="button" class='btn btn-primary' data-toggle="modal" data-target="#myModal_<%= product.id %>">
Show Product
</button>
<% end %>

 <!-- Modal -->
    <div id="myModal_<%= product.id %>" class="modal fade" role="dialog">
        <div class="modal-dialog">

        <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title text-left">BuyOffer</h4>
            </div>

            <div class="modal-body">

          <% product.buy_offers.each do |buyoffer| %>
            <%= buyoffer.total %>
          <% end %>

            </div>
          </div>
        </div>
    </div>

【问题讨论】:

    标签: ruby-on-rails ruby model-view-controller bootstrap-modal


    【解决方案1】:

    你可以使用will_paginategem来实现这个

    <% product.buy_offers.each do |buyoffer| %>
         <%= buyoffer.total %>
     <% end %>
    

    将上面的代码替换为

       <% buyoffers = product.buy_offers.paginate(page: params[:page], :per_page => 10) %>
          <% buyoffers.each do |buyoffer| %>
            <%= buyoffer.total %>
          <% end %>
       <%= will_paginate buyoffers %>
    

    【讨论】:

      猜你喜欢
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 2013-03-15
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 1970-01-01
      相关资源
      最近更新 更多