对 SEO 的"嵌套"轨道路线进行分页



我需要弄清楚如何正确使用路由来创建一个url结构,如:

项目/页面/2

项目/过期/页面/2

我有items/page/2工作,然后我有这个,我想纠正:项目/过期吗?= 2页

我正在使用Kaminari为rails 4.2提供漂亮的url结构。https://github.com/amatsuda/kaminari/creating-friendly-urls-and-caching

我的控制器有两个动作:索引和过期

items下的视图是index.html.haml和expired.html.haml

routes.rb

concern :paginatable do
  get '(page/:page)', :action => :index, :on => :collection, :as => ''
end
concern :expired_paginatable do
  get '(page/:page)', :action => :expired, :on => :collection, :as => ''
end
get 'items/expired', to: "items#expired", :concerns => :expired_paginatable
resources :items, :concerns => :paginatable

我的观点都有:

= paginate @items

我知道我不需要两个问题,但我想我会试一试。

我最终将我的资源块更改为:

resources :items do
  collection do
    get 'expired/page/:page', :action => :expired
    get :expired
  end
  concerns :paginatable
end

下降:

concern :expired_paginatable do
  get '(page/:page)', :action => :expired, :on => :collection, :as => ''
end
get 'items/expired', to: "items#expired", :concerns => :expired_paginatable
resources :items, :concerns => :paginatable

最新更新