A
A
Andrey Romanov2014-04-10 16:45:41
Ruby on Rails
Andrey Romanov, 2014-04-10 16:45:41

How to set up routing in Rails?

Hello everybody.
There was a need to make url's of the following form: example.com/category_name/post_name
I wrote the following in the routes.rb file:

resources :categories do
    resources :posts
end

But such parameters give such URLs: example.com/categories/category_name/post_name
Question: how to remove the extra word categories in the URL? Defining all routes manually (not through resources) is somehow unaesthetic.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arkady Butermanov, 2014-04-10
@Scorpion97

resources :categories, :path => '' do
  resources :posts, :path => ''
end

A
Alexey, 2014-04-10
@fuCtor

get '/:category/:post' => 'controller#action'
Replace with the necessary one only, and so all this is written in the documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question