mislav-will_paginate(will_paginate) doesn''t work after search. servers_controller.rb def index @servers = Server.paginate(:page => params[:page], :per_page => 20, :order => ''device_id ASC'') respond_to do |format| format.html # index.html.erb format.xml { render :xml => @servers } end end def search @servers = Server.paginate(:page => params[:page], :per_page => 20, :order => ''device_id ASC'', :conditions => ["hostname like ?", "%"+params[:keyword]+"%"]) render :action => ''index'' end index.html.erb <%= will_paginate @servers %> paginate works fine for index, but after search, only first page is showed, when I click "next" or "2", the error appears. ActiveRecord::RecordNotFound (Couldn''t find Server with ID=search): app/controllers/servers_controller.rb:26:in `show'' It seems like paginate doesn''t know, params[:keyword], I haven''t done anything for "def show" in servers_controller.rb. def show @server = Server.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @server } end end How can I resolve this issue? -duke -- Posted via http://www.ruby-forum.com/.
Quoting Duke Yamamoto <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: [snip]> paginate works fine for index, but after search, only first page is > showed, > when I click "next" or "2", the error appears. > ActiveRecord::RecordNotFound (Couldn''t find Server with ID=search): > app/controllers/servers_controller.rb:26:in `show'' >[snip] Check your routing and URLs. I suspect they don''t match for search. HTH, Jeffrey
Jeffrey L. Taylor wrote:> Quoting Duke Yamamoto <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > [snip] >> paginate works fine for index, but after search, only first page is >> showed, >> when I click "next" or "2", the error appears. >> ActiveRecord::RecordNotFound (Couldn''t find Server with ID=search): >> app/controllers/servers_controller.rb:26:in `show'' >> > [snip] > > Check your routing and URLs. I suspect they don''t match for search. > > HTH, > JeffreyI added it to routes.rb map.search ''/search'', :controller => ''servers'', :action => ''search'' But I receive different error at this time, TypeError in ServersController#search can''t convert nil into String It seems like paginate doesn''t no what keyword has been used for search on next page, so I changed view from <%= will_paginate @servers %> to <%= will_paginate @servers, :params => {:keyword =>params[:keyword]} %> ":params => {:keyword =>params[:keyword]}" this part is hand the parameter to the next page. What I have done is created search.html.erb instead of using index.html.erb, the only difference between search and index is ":params => {:keyword =>params[:keyword]}" and added routes.rb, and modified "def search" in servers_controller.rb respond_to do |format| format.html # index.html.erb format.xml { render :xml => @servers } end instead of render :action => ''index'' It works fine now. Thank you Jeffrey. -- Posted via http://www.ruby-forum.com/.