0

I want to have the url /community so here is what I did. I created the controller: CommunitiesController and have this in my routes:

get 'community' => 'communities#index'

Did I set this up incorrectly? The problem I'm having is I now want to add the kaminari pagination gym but the naming mismatch is causing this not to work:

  get 'community' => 'communities#index'
  resources :communities do
    get 'page/:page', action: :index, on: :collection
  end

as it wants me to user /communities/page/1 when I want to use /community/page/1

What would be the correct way to setup a controller and route with this use case?

halfer
  • 19,824
  • 17
  • 99
  • 186
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012

2 Answers2

0

I would go with

get 'community' => 'communities#index'
get 'community/page/:page' => 'communities#index'

But you may need to tweak paginate method and pass explicit params to make it work. I am not sure if this will be required, but it looks something like this

<%= paginate(@communities, params: { controller: 'communities', action: 'index' } %>
Michał Młoźniak
  • 5,466
  • 2
  • 22
  • 38
0

The more "resourceful" way of declaring your original community route is as follows:

resources :communities, path: "community", only: "index"

Then you can add the Kaminari route according like this:

resources :communities, path: "community", only: "index" do
  get "page/:page", action: :index, on: :collection
end

For further explanation, read the very helpful Rails Routing from the Outside In guide.

Matt Brictson
  • 10,904
  • 1
  • 38
  • 43