Forum: Ruby on Rails will_paginate problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9b0a6eb6d86a395f9da2f6b48fdecd8e?d=identicon&s=25 engamocap (Guest)
on 2009-03-12 10:31
(Received via mailing list)
I searched in Internet (http://wiki.github.com/mislav/will_paginate/
simple-search and http://railscasts.com/episodes/51), but I can't
solve my problem about pagination. The first page is ok, but when I
click the “Next page” or any other page link, I lose the FIELD1,
FIELD2, FIELD3 parameter(s). Can you help me? Thank you very much.


class Model < ActiveRecord::Base

  ...

  def self.display(cond, par, page)
    paginate :all,
             :include => [:table1, :table2],
             :conditions => [cond, par].flatten,
             :page => page,
             :per_page => 10
  end

end
--------
class ModelController < ApplicationController

  def start
    ...
  end
  ...

  def view
    condition = "1=1"
    param = []
    (condition+=" AND models.FIELD1=?"; param << params
[:FIELD1].values) if params[:FIELD1]
    (condition+=" AND models.FIELD2=?"; param << params
[:FIELD2].values) if params[:FIELD2]
    (condition+=" AND models.FIELD3=?"; param << params
[:FIELD3].values) if params[:FIELD3]
    @items = Model.display(condition, param, params[:page])
  end

end
--------
view.html.erb

  ...
<%= will_paginate @items %>
--------
start.html.erb
  ...
  <% form_tag(:action => "view", :method => "get") do %>
    ... # define FIELD1, FIELD2 and FIELD3
  <% end %>
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-12 10:53
Whether FIELD1, FIELD2,FIELD3 are table column heading or values?
9b0a6eb6d86a395f9da2f6b48fdecd8e?d=identicon&s=25 engamocap (Guest)
on 2009-03-12 11:35
(Received via mailing list)
FIELD1, FIELD2 and FIELD3 are table columns and values. They have the
same names.

On Mar 12, 10:53 am, Priya Buvan <rails-mailing-l...@andreas-s.net>
0348be81e22f24afdaa6e4f137aa9dfc?d=identicon&s=25 Priya Buvan (priyadharsini)
on 2009-03-12 13:38
I think you are not getting my question.. I asked whether FIELD1,
FIELD2,FIELD3 are table column headings? Like

Eg:

S.No Name RollNo Address
  1   xx   xxx     xxxx

S.No Name RollNo Address are column heading. Need to show this in all
pages?
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-03-12 17:39
(Received via mailing list)
On Mar 12, 2009, at 4:54 AM, engamocap wrote:
>  def self.display(cond, par, page)
>
>    (condition+=" AND models.FIELD2=?"; param << params
>  ...
> <%= will_paginate @items %>
> --------
> start.html.erb
>  ...
>  <% form_tag(:action => "view", :method => "get") do %>
>    ... # define FIELD1, FIELD2 and FIELD3
>  <% end %>


<%= will_paginate @items, :params => params %>

or a suitable subset of the items from params

:params => params.reject {|k,v| k !~ /FIELD/ }

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
This topic is locked and can not be replied to.