Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken Previous and Next links #104

Open
TheSynthMaster opened this issue Feb 17, 2011 · 3 comments
Open

Broken Previous and Next links #104

TheSynthMaster opened this issue Feb 17, 2011 · 3 comments

Comments

@TheSynthMaster
Copy link

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 &raquo;"     : link_to("Next &raquo;"    ,workorders_path + "?" + @url_param_next)),
          :previous_label => (@workorders.previous_page == nil ? "&laquo; Previous" : link_to("&laquo; 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"
@mislav
Copy link
Owner

mislav commented Feb 19, 2011

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?

@TheSynthMaster
Copy link
Author

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

@TheSynthMaster
Copy link
Author

Any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants