Rails will_paginate custom route

前端 未结 3 1734
庸人自扰
庸人自扰 2020-12-31 20:32

How can I use will_paginate with a custom route?

I have the following in my routes:

map.connect \'human-readable/:name\', :controller => :tags, :a         


        
相关标签:
3条回答
  • 2020-12-31 21:03

    You need define this route too

    
    map.connect 'human-readable/:name', :controller => :tags, :action => 'show'
    map.connect 'human-readable/:name/page/:page', :controller => :tags, :action => 'show'
    

    0 讨论(0)
  • 2020-12-31 21:21

    Another option is to use param in will_paginate but passing in the parameter like so:

    <%= will_paginate @products, :params => {:controller => 'human-readable', :action => 'show', :name => 'xyz'} %>
    

    and now your links will look like human-readable/xyz?page=2...

    0 讨论(0)
  • 2020-12-31 21:26

    The will_paginate view helper has a :params option for overriding the default link generation.

    Change your routes configuration:

    map.human_readable_tag '/human-readable/:name', 
         :controller => :tags, :action => 'show'
    

    Invoke the will_paginate view helper as follows:

    <%= will_paginate @tag_list, 
         :params => {:controller => human_readable_tag_path(@tag_name) } %>
    

    Make sure you have set the @tag_name variable in your controller.

    For more information read the will_paginate view helper documentation.

    The :params option passed to the helper is used to invoke url_for. So read the url_for documentation for how we faked a controller name.

    0 讨论(0)
提交回复
热议问题