【问题标题】:paginate 'nested' rails routes for seo为 seo 分页“嵌套”rails 路线
【发布时间】:2015-07-22 21:24:37
【问题描述】:

我需要弄清楚如何正确使用路由来创建这样的 url 结构:

项目/页面/2

items/expired/page/2

我有 items/page/2 工作,然后我有这个我想更正: items/expired?page=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

我知道我不需要两个顾虑,但我想我会尝试一下。

【问题讨论】:

    标签: ruby-on-rails routes kaminari


    【解决方案1】:

    我最终将资源块更改为:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      相关资源
      最近更新 更多