如何添加自定义 URL

How to add custom URLs

如何添加自定义 URL,例如 localhost:3000/one_hour/page/2 而不是 localhost:3000/one_hour?page=2

get '/one_hour', to: 'feed_entries#one_hour'

我用Rails4、Kaminari和mongoid

routes.rb

Rails.application.routes.draw do
  concern :paginatable do
    get '(page/:page)', :action => :index, :on => :collection, :as => ''
  end
  resources :feed_entries, path: 'news', :concerns => :paginatable
  get '/one_hour', to: 'feed_entries#one_hour'
end

feed_entries_controller.rb

class FeedEntriesController < ApplicationController
  one_hour
    @feed_entries = FeedEntry.includes(:source).one_hour.page(params[:page])
  end
end

我找到了解决方案:

在routes.rb

get 'one_hour/(page/:page)', controller: 'feed_entries', action: 'one_hour', to: 'feed_entries#one_hour', as: :one_hour