Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Behavior of view helper is incorrect if URL includes "@"

#262

Given: * Rails 2.1.2 * will_paginate 2.3.6

config/routes.rb:


ActionController::Routing::Routes.draw do |map|
  RE_USER_LOGIN = /[^\/]+/

  map.with_options :controller => "user_blogs", :action => "index" do |r|
    r.connect "blogs/:user_login/pages/:page", :requirements => { :user_login => RE_USER_LOGIN }
    r.connect "blogs/:user_login", :requirements => { :user_login => RE_USER_LOGIN }
  end
  ....
end

app/views/user_blogs/index.html.erb:


  ...
  <%= will_paginate @news %>
  ...

I get page links "/blogs/2Andrex/pages/@", "/blogs/3Andrex/pages/@" when I visited "/blogs/@Andrex".

The routing works fine:


$ ./script/console
>> irb ActionController::Routing::Routes
irb: warn: can't alias context from irb_context.

>> recognize_path "/blogs/@Andrex/pages/2"
=> {:user_login=>"@Andrex", :controller=>"user_blogs", :page=>"2", :action=>"index"}

>> generate :user_login=>"@Andrex", :controller=>"user_blogs", :page=>"2", :action=>"index"
=> "/blogs/@Andrex/pages/2"

Reported by Anton Ageev · January 29th, 2009 @ 08:10 AM

State: open
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Mislav
    Mislav
    • State changed from new to resolved

    That is because of the internal "optimization" when generating URLs.

    You can either use will_paginate 3.0 (not yet released, find it in the "agnostic" branch) or this monkeypatch:

    
    WillPaginate::LinkRenderer.class_eval do
      protected
    
      def url_for(page)
        url_params = {}
        # page links should preserve GET parameters
        stringified_merge url_params, @template.params if @template.request.get?
        stringified_merge url_params, @options[:params] if @options[:params]
        
        if complex = param_name.index(/[^\w-]/)
          page_param = (defined?(CGIMethods) ? CGIMethods : ActionController::AbstractRequest).
            parse_query_parameters("#{param_name}=#{page}")
          
          stringified_merge url_params, page_param
        else
          url_params[param_name] = page
        end
    
        @template.url_for(url_params)
      end
    
    end
    

    January 29th, 2009 @ 11:58 AM

  2. Mislav
    Mislav
    • State changed from resolved to open

    On the other hand, lets rather leave this ticket open.

    January 29th, 2009 @ 12:03 PM

  3. Anton Ageev
    Anton Ageev

    The monkeypatch brokes all page links. I get "/blogs/@Andrex" instead of "/blogs/@Andres/pages/(\d+)" for any page.

    January 29th, 2009 @ 03:58 PM

  4. Mislav
    Mislav

    Ouch. Then how about

    
    WillPaginate::LinkRenderer.class_eval do
      protected
    
      def url_for(page)
        url_params = {}
        # page links should preserve GET parameters
        stringified_merge url_params, @template.params if @template.request.get?
        stringified_merge url_params, @options[:params] if @options[:params]    
        url_params[param_name.to_sym] = page
    
        @template.url_for(url_params)
      end
    
    end
    

    January 29th, 2009 @ 08:26 PM

  5. Anton Ageev

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.