neo
neo

Reputation: 4116

Rails routes change URL with ressources

I have the following in my routes:

resources :collection_pages, :only => [:show, :index]

Right now its going to wwww.mysite.com/collection_pages for index

and collection_pages/:id for show

I need it to go to /collections instead for index

and /collection/:id for show

I tried path: :collections , but its not behaving as I'd like.

What's the best way to achieve this using ressources?

Upvotes: 0

Views: 780

Answers (1)

craig.kaminsky
craig.kaminsky

Reputation: 5598

Along with the SO answer @Tamer.Shlash notes, you could use custom matchers in your routes file:

match '/collection', to: 'collection_pages#index', as: 'collection_index'
match '/collection/:id', to: 'collection_pages#show', as: 'collection_show'

Adding the as: 'xxxx' to the match allows you to use friendly path and url helpers in your views:

redirect_to collection_index_path

Upvotes: 2

Related Questions