On Mar 12, 2009, at 4:54 AM, engamocap wrote:
> 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 %>
<%= 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
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---