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.

Ignores page :params in merb

#259

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.

Reported by Jamie Wilson · January 12th, 2009 @ 09:46 PM

State: new
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Mislav
    Mislav

    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

    January 12th, 2009 @ 11:48 PM

  2. Jamie Wilson
    Jamie Wilson

    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
    

    January 13th, 2009 @ 09:02 PM

  3. Mislav
    Mislav

    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 Double page params when using merb 1.0.6.1

    January 14th, 2009 @ 12:38 AM

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.