如何添加自定义网址

时间:2015-02-19 20:20:13

标签: ruby-on-rails mongoid kaminari

如何添加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

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

在routes.rb

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