我使用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.html
和
/文章/索引.html
?
谢谢
更新
我只是加了一句
map.connect '/posts/index/', :controller => 'redirect', :url => '/posts/'
我再也不会收到重复的页面了。
但是,我仍然不知道为什么
/文章/索引.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