如何添加localhost:3000/one_hour/page/2
而非localhost:3000/one_hour?page=2
到get '/one_hour', to: 'feed_entries#one_hour'
我使用Rails 4,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
答案 0 :(得分:0)
我找到了解决方案:
在routes.rb
中 get 'one_hour/(page/:page)', controller: 'feed_entries', action: 'one_hour', to: 'feed_entries#one_hour', as: :one_hour