Topic: paginate and lots of include rules

I have this

    @infostwo_pages, @infostwo = paginate(:info, :include => :medialogs, :conditions => ["Licensable = 'Yes'"] + ["Synopsis_Content LIKE ? or Address_Track LIKE ?"] + ["%#{params[:query]}%"] * 2, :per_page => 10)

On the first page it shows zilchand the next page just plain out ignores the pagnation ....

somethin funky lies their

Re: paginate and lots of include rules

Make sure you are passing the "query" parameter in all pagination links. Otherwise it will be lost.

Railscasts - Free Ruby on Rails Screencasts

Re: paginate and lots of include rules

ah... rats I thought I was doing that

Re: paginate and lots of include rules

any chance I could get a hint ?
I see the massive find and paggnate on the end of it and the duo assigning on the @infostwo_pages
But I just dont get what is wrong after that.

An array is created and asigned to the objects... Why does it not repeat....

Re: paginate and lots of include rules

It depends how you are generating the links in the view. If you are using the pagination_links method, you would do this:

<%= pagination_links @infostwo_pages, :params=> { :query => params[:query] } %>

Last edited by ryanb (2006-11-30 19:02:36)

Railscasts - Free Ruby on Rails Screencasts

Re: paginate and lots of include rules

Hmmm that returns results but only on the second and third pages if my search is lucky..
The first page results are blank

I read alot how people are not liking paginate, what other options are their ? I read something about  edge and ajax... No clue though, I just want it to work without a trillion hacks

Re: paginate and lots of include rules

The built in pagination methods do have problems, but they aren't that bad. They really are the simplest approach at the moment, so I recommend going with it at first. You can always move to something else later if they don't meet your needs.

As for your problem. I don't know why it's not working. Can you post more of your code?

Railscasts - Free Ruby on Rails Screencasts

Re: paginate and lots of include rules

Ok here goes

Search results view

<style>
    xdiv { border: solid 1px; }
    body {
    font: 1.4em 'Lucida Grande', LucidaGrande, Lucida, Helvetica, Arial, sans-serif;
    xbackground: #cccccc url(images/tile1.jpg) repeat;
    }
    #fax { margin: 100 auto 0 auto; width:780px;}
    #logo { margin: 0 auto; width: 770px; height:100px;
    xbackground: transparent url(images/logo.png) no-repeat;
    }
    #fax span { margin-left: -3000px; }
    #search { text-align: center; }
    #searchbox { margin: 1em auto; width: 750px; height: 40px;
    xbackground: #8c8c8c; }
    a { border: solid 0px; }
    /*
    Coffee with milk
    Table design by Roger Johansson, 456 Berea Street
    www.456bereastreet.com
    ================================================*/
    table {
        width: 760px;
    border: solid 0px;
    font:normal 0.44em "Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
    border-collapse:separate;
    xbackground: #b9927c;
    border-spacing:0;
    margin:0 0 1em;
    color:#000;
    }
    table a {
    color:#523A0B;
    text-decoration:none;
    border-bottom:1px dotted;
    }
    table a:visited {
    color:#444;
    font-weight:normal;
    }
    table a:visited:after {
    content:"\00A0\221A";
    }
    table a:hover {
    border-bottom-style:solid;
    }
    thead td, tbody td {
    padding-top: 10px;
    padding-bottom: 10px;
    padding-left: 12px;
    }
    thead td, thead th {
    font-size: 1.6em;
    text-transform: capitalize;
    }
    thead th,
    thead td,
    tfoot th,
    tfoot td {
    border:1px solid #523A0B;
    border-width:1px 0;
    xbackground:#e9b5ae;
    }
    th {
    font-weight:bold;
    line-height:normal;
    padding:0.25em 0.5em;
    text-align:left;
    }
    tbody th,
    td {
    width:200px;
    padding:0.25em 0.5em;
    text-align:left;
    vertical-align:top;
    }
    tbody th {
    font-weight:normal;
    white-space:nowrap;
    }
    tbody th a:link,
    tbody th a:visited {
    font-weight:bold;
    }
    tbody td,
    tbody th {
    border:1px solid #fff;
    border-width:1px 0;
    }
    tbody tr.odd th,
    tbody tr.odd td {
    border-color:#EBE5D9;
    xbackground:#F7F4EE;
    }
    tbody tr:hover td,
    tbody tr:hover th {
    xbackground:#ffffee;
    border-color:#523A0B;
    }
    caption {
    font-family:Georgia,Times,serif;
    font-weight:normal;
    font-size:1.4em;
    text-align:left;
    margin:0;
    padding:0.5em 0.25em;
    }
    #searchresults {margin:  0 auto; width: 760px;}
</style>

     


         <%= pagination_links @infostwo_pages, :params=> { :query => params[:query] } %>
      <%#     pagination_links(paginator, options={}, html_options={})  %>
<%# { :name => :page, :window_size => 2, :always_show_anchors => true, :link_to_current_page => false, :params => {} %>


<% for info in @infostwo %> 
<% medialogs = info.medialogs.find(:all, :conditions => ['shotdescription LIKE ?', '%' + params[:query].to_s + '%']) %>
<% for cat in medialogs %>     
<table>   

    <tbody> 
        <thead>
            <tr>
                <td colspan="6" scope="col">Shot Description</td>
            </tr>
        </thead>

        <tr>
            <td colspan="6"><%= cat.shotdescription %></td>

        </tr>
        <thead> <tr>
            <td width="14">Barcode</td>
            <td width="22">Start</td>
            <td width="19">End</td>
            <td width="25">Duration</td>
            <td width="23">Shot Type</td>
            <td width="57">Searched by</td>
        </tr></thead>
        <tr>   
             <td><%= cat.id %></td>
            <td><%= cat.info_id %></td>
            <td><%= cat.shottype %></td>
            <td><%= cat.start %></td>
            <td><%= cat.end %></td>
            <td><%= cat.duration %></td>
            <td><%= cat.searchedby %></td> 
            <td widtd="29" scope="col"><%= info.Licensable %></td>                     
        
        </tr>
    </tbody>
          </table>   
    <% end %>       
             
  <% if medialogs.empty? && info.Synopsis_Content.include?(params[:query]) %>
                         <table  border="1">
<thead>
<tr>
  <td widtd="155" scope="col"><%= info.Subject_Title %></td>
  <td widtd="29" scope="col"><%= info.id %></td>
<td widtd="29" scope="col"><%= info.Licensable %></td>                     
</tr>   
</thead>
<tbody>
<tr>
  <td colspan="2"><%= info.Synopsis_Content %></td>
</tr>
</tbody>   
</table>
    <% end %>
   
      <% end %>


Search form
<h1>SEARCH</h1>
<div id="searchbar">
    <%= start_form_tag :action => 'infomoxlist' %>
    <%= text_field_tag ("query", @params['query'], :size => 40 ) %>
    <br />
    <%= check_box_tag 'filters[shotdescription]', checked = true, options = {} %> Bar Code
    <%= check_box_tag 'filters[Synopsis_Content]', checked = true, options = {} %> id
    <%= check_box_tag 'filters[Address_Track]', checked = true, options = {} %> Shot description
    <%= submit_tag 'Search' %>
    <%= end_form_tag %>

Controller
@infostwo_pages, @infostwo = paginate(:info, :include => :medialogs, :conditions => ["Licensable = 'Yes'"] + ["Synopsis_Content LIKE ? or Address_Track LIKE ?"] + ["%#{params[:query]}%"] * 2, :per_page => 10)

#@per_page = 30
#      @infostwo = Info.find(:all, :include => :medialogs, :conditions => ["Licensable = 'Yes'"] + ["Synopsis_Content LIKE ? or Address_Track LIKE ?"] + ["%#{params[:query]}%"] * 2)
#    @infostwo_pages, @infostwo = paginate_collection @infostwo, :per_page => @per_page
#       #@infos_pages, @infostwo = paginate :info,:include => :medialogs, :per_page => 4             
#


Test helper also tried from else where
   def paginate_collection(coll, options = {}) 
      # Grab params and fix em up
      per = options[:per_page].to_i
      page = (params[:page] || 1).to_i
      offset = (page - 1) * per

      # Create a Paginator based on the collection data
      pages = Paginator.new self, coll.size, per, page

      # Grab the sub-set of the collection
      paged = coll[offset..(offset + per - 1)]

      return [pages, paged]
    end


Forgive me if things are off I have made lots of tests since this last simi working code.
I am now prepping to test out http://cardboardrocket.com/2006/09/06/p … en-sexier/

Re: paginate and lots of include rules

You are paginating the info models, but then you are doing a 2nd search for each Info and finding the medialogs. This is probably why some pages have more results than others.

Railscasts - Free Ruby on Rails Screencasts

Re: paginate and lots of include rules

Hmmm  I played with it all night and just came to a raoring headache..

I know as much that the search needs to be in one query with the include that way the paginate works on the one joined search.
But it also noods to give if else varables to the view to deside if I need to keep the first result tables results or the others

I tried act_as_ferret and full text search http://wiki.rubyonrails.org/rails/pages/TextSearch
my own hash from all of the tips

But I still have a glooming 20,000 row  goal and know if normal paginate does not work it will be far to slow