2

I am having some difficulties getting the Kaminari gem to work with my Bootstrap modal. I know that it needs to work primarily with Ajax, but I'm not quite sure what to do on this one.

Specifically, I have over 800 images that are supposed to load in the Modal. But, right now, all those images are loading at once, causing a long loading time.

Here's what I currently have:

new.html.erb

  # basic html items
 <%= render "image_modal" %>

_image_modal.html.erb

 <div class="modal fade" id="choosePicture" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
   <div class="modal-content">
     <div class="modal-header">
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
       <h4 class="modal-title">Choose Your Image</h4>
     </div>
     <div class="modal-body">
      <div class="row">
          <% @images_by_filename.each do |image|  %>
          <div class=" col-xs-3">
              <div class="thumbnail">
                <%= image_tag image.picture(:square), :title => image.name, :id => image.id, :image_url => image.picture(:thumb), :class => "list_thumb image-select style_image" %>
              </div>
          </div>
          <% end  %>
      </div>
  </div>
  <div class="modal-footer">
   <div class="form-group">
    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
   </div>
  </div>
</div><!-- /.modal-content -->

images_controller.rb

class ImagesController < ApplicationController
  def new
    @template = Template.new
    @groups = Group.all
    @images = @images_by_filename
    @template.template_assignments.build
  end
 end

How could I incorporate Kaminari to work within this modal, separately? When I try to implement the pagination, it ends up refreshing the entire page, as opposed to just within the modal.

Any help on this would be great!

Dodinas
  • 6,705
  • 22
  • 76
  • 108

1 Answers1

0

Some code is missing in controller and view files.

images_controller.rb

@images = @images_by_filename.page(params[:page]).per(number_of_records_per_page)

_image_modal.html.erb

= paginate @images

You can refer http://railscasts.com/episodes/254-pagination-with-kaminari for more help.

Hope this will help you.

Parthiv
  • 828
  • 9
  • 20
  • Hi Parthiv: Thanks for your reply. Unfortunately, this did not help. As previously mentioned, when I implement Kaminari (using like-code you provided), it results in the entire page being reloading, not just the single modal. Thus, the entire page reloads, resulting in a "closed modal" and an entire page refresh. I am trying to change pages within the modal without a page refresh. – Dodinas Jul 01 '14 at 15:01