will_paginate
will_paginate copied to clipboard
Broken Previous and Next links
ruby 1.8 - rails 2.3.8 - will_paginate 2.3.15
We use will_paginate extensively in our application (an asset management and trouble ticketing tool) It works pretty nice, except for an app called workorders where the next and previous links in index.html.erb are broken. In particular link are of the type http://1.2.3.4/workorders/index/? and params following The correct link is without the /index/ I made a workaround by creating the next-previous links myself in the index view and using the :next_label and :previous_label parameters to pass the links to will_paginate:
@url_param = ""
params.each { |k,v| @url_param << (k == "page" ? "" : (k + "=" + (v == nil ? "" : url_encode(v)) + "&")) }
@url_param_next = h (@url_param + "page=" + (@workorders.next_page == nil ? "" : @workorders.next_page.to_s))
@url_param_prev = h (@url_param + "page=" + (@workorders.previous_page == nil ? "" : @workorders.previous_page.to_s))
will_paginate @workorders, :page_links => false, :container =>false,
:next_label => (@workorders.next_page == nil ? "Next »" : link_to("Next »" ,workorders_path + "?" + @url_param_next)),
:previous_label => (@workorders.previous_page == nil ? "« Previous" : link_to("« Previous",workorders_path + "?" + @url_param_prev))
In the controller the call to will_paginate is:
@workorders = current_user.service.workorders.paginate :per_page=>20,
:page=>params[:page],
:include => [:asset] ,
:conditions => ["(workorders.id = ? #{params[:id]=='' ? 'or 1=1':''}) and (upper(workorders.description) like ? #{params[:description]!='' ? '' : 'or workorders.description is null'}) and (workorders.status like ? ) and (workorders.worktype like ? ) and (assets.code like ? #{params[:asset_code]=='' ? 'or 1=1':''}) and ((workorders.created_at >= ? and workorders.created_at < ?) #{!created_from ? 'or 1=1':''})", params[:id].to_i,params[:description].upcase+"%",params[:status].upcase+"%",params[:worktype].upcase+"%",params[:asset_code].upcase+"%",created_from,created_to ],
:order => "workorders.id desc"
Can I see your routes definitions related to "workorders"? Also I'd like to know where in the routes file is the default route (the one generated with Rails, which handles all controllers/actions)
Another question: I'm guessing that this pagination is rendered during the "views/workorders/index.html" template, right?
Yes, views/workorders/index.html.erb
These are the routes definitions:
ActionController::Routing::Routes.draw do |map|
# ...
map.resources :workorders
# ...
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
map.connect '' , :controller=>"login", :action=>"login"
end
Any news?