如何更改will_paginate URL? [英] How to change will_paginate URLs?

查看:76
本文介绍了如何更改will_paginate URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 will_paginate 链接从 / list?page = 1 的格式更改为 / list / page / 1 。我已经为此设置了路由,但是 will_paginate 在链接中使用查询字符串,而不是我漂亮的URL样式。

I'm trying to change the will_paginate links from the format of /list?page=1 to /list/page/1. I have the routes setup right for this, but will_paginate is using the query string in links rather than my pretty URL style. How to tell it otherwise?

我正在使用will_paginate 2.3.16 和Rails 2.3.14 。 / p>

I'm using will_paginate 2.3.16 and Rails 2.3.14.

推荐答案

will_paginate使用 url_for 助手。如果定义包含它使用的参数的路由,它将生成漂亮的URL。

will_paginate uses the url_for helper. If you define routes containing the parameters it uses, it should generate pretty urls.

map.connect '/lists/page/:page', :controller => 'lists', :action => 'index'

请确保您在任何路径上上方定义此路径也可以与您的控制器操作匹配。甚至更好:排除像这样的索引操作:

Please make sure, you define this route above any routes that could also match your controller action. Even better: exclude the index action like this:

map.resources :lists, :except => [:index]

这篇关于如何更改will_paginate URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆