我使用will_paginate插件。Rails will_paginate路由缓存重复页面
在奥德生成我可以缓存(的/posts/index/2
代替/posts?page=2
)途径添加以下到我的routes.rb:
map.connect '/posts/index/1', :controller => 'redirect', :url => '/posts/'
map.connect 'posts/index/:page',
:controller => 'posts',
:action => 'index',
:requirements => {:page => /\d+/ },
:page => nil
第一行重定向/posts/index/1
到/posts/
使用重定向控制器,以避免有一个重复的页面。
我设置'posts/index/:page'
规则的方式有什么问题吗?
我认为加入:requirements => {:page => /\d+/ }
将确保/post/index/
没有:page
参数不应该工作,但/posts/index.html
得到缓存。
如何将/posts/index/
重定向到/posts/
以避免同时有/posts.html
和/posts/index.html
?
感谢
UPDATE
我只是简单地添加
map.connect '/posts/index/', :controller => 'redirect', :url => '/posts/'
而且我没有得到重复的网页了。
但是,我仍然不明白我为什么会得到/posts/index.html
。欢迎任何有关如何使这条规则更加简洁的解释或建议;)!
map.connect '/posts/index/1', :controller => 'redirect', :url => '/posts/'
map.connect '/posts/index/', :controller => 'redirect', :url => '/posts/'
map.connect 'posts/index/:page',
:controller => 'posts',
:action => 'index',
:requirements => {:page => /\d+/ },
:page => nil
谢谢你,我一定会尝试,并回来更新这个线程。 – deb 2010-02-26 22:54:08