Eugene
Eugene

Reputation: 689

Simplify url in rails

I need just simplify url in my rails app. /nature instead /categories/nature

My routes.rb:

match 'categories/:id' => 'categories#show'

Upvotes: 0

Views: 108

Answers (1)

Erez Rabih
Erez Rabih

Reputation: 15788

match ':id' => 'categories#show'

This will make any request to '/something' to categories controller with show action though so you have to take that into account.

If I were you I'd do it more like that:

match ':id' => 'categories#show',:constraints => { :id => /nature|sports|architecture|people|.../ }

This way you can still use '/something' routes as you wish as long they don't match any of the available categories.

Upvotes: 1

Related Questions