#259 new
Jamie Wilson

Ignores page :params in merb

Reported by Jamie Wilson | 2009-01-12 21:46:38 UTC

Using the agnostic branch. Trying to pass in explicit url params, which seem to be ignored when using will_paginate under merb.

I think doing something like


  def url(page)
    params = @template.request.params.except(:action, :controller).merge('page' => page)
    params.merge!(@options[:params]) if @options[:params]

    @template.url(params)
  end

fixes the problem.

There's quite probably a better way to do it though.

Thanks.

Comments and changes to this ticket

  • Mislav

    Mislav 2009-01-12 23:48:41 UTC

    Can you try out something like this, see if it's OK?

    
    WillPaginate::ViewHelpers::LinkRenderer.class_eval do
      protected
      
      def default_url_params
        {}
      end
      
      def url(page)
        @base_url_params ||= begin
          url_params = base_url_params
          merge_optional_params(url_params)
          url_params
        end
        
        url_params = @base_url_params.dup
        add_current_page_param(url_params, page)
        
        @template.url(:this, params)
      end
      
      def base_url_params
        url_params = default_url_params
        # page links should preserve GET parameters
        symbolized_update(url_params, @template.request.params.except(:action, :controller)) if get_request?
        url_params
      end
      
      def merge_optional_params(url_params)
        symbolized_update(url_params, @options[:params]) if @options[:params]
      end
      
      def add_current_page_param(url_params, page)
        url_params.merge('page' => page)
      end
      
      def get_request?
        @template.request.method == :get
      end
    end
    

    These are the things I actually planned to build into LinkRenderer (sans Merb-specific stuff). Currently they're only available in ActionView (which is wrong).

    Thanks for reporting

  • Jamie Wilson

    Jamie Wilson 2009-01-13 21:02:57 UTC

    I took what you sent and made a couple of little tweaks. This seems to work better for me:

    
    WillPaginate::ViewHelpers::LinkRenderer.class_eval do
     protected
    
     def default_url_params
      {}
     end
    
     def url(page)
      @base_url_params ||= begin
        url_params = base_url_params
        merge_optional_params(url_params)
        url_params
      end
    
      url_params = @base_url_params.dup
      url_params = add_current_page_param(url_params, page)
    
      @template.url(url_params)
     end
    
     def base_url_params
      url_params = default_url_params
      # page links should preserve GET parameters
      symbolized_update(url_params, @template.request.params.except(:action, :controller)) if get_request?
      url_params
     end
    
     def merge_optional_params(url_params)
      symbolized_update(url_params, @options[:params]) if @options[:params]
     end
    
     def add_current_page_param(url_params, page)
      url_params.merge(:page => page)
     end
    
     def get_request?
      @template.request.method == :get
     end
    end
    
  • Mislav

    Mislav 2009-01-14 00:38:55 UTC

    Thanks for reviewing. I think we have to use string key "page" instead of symbol because otherwise the page parameter could get duplicated -- see #256

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.

New ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Everyone's favorite Ruby library for pagination of practically anything!

People watching this ticket

Pages