1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-06 08:38:01 +00:00

Add Customize The Path Of A Resource Route as a rails til

This commit is contained in:
jbranchaud
2019-11-18 09:40:40 -06:00
parent c9d6faadc0
commit bd41a371b1
2 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
# Customize The Path Of A Resource Route
The `:path` option allows you to customize the path used by a resource route in
Rails' `config/routes.rb` file. This is handy if you have a multi-word resource
that you would like to use dashes in the path.
For instance
```ruby
resources :audio_books
```
would have paths like `/audio_books` and `/audio_books/:id`.
By specifying the `:path` option
```ruby
resources :audio_books, path: 'audio-books'
```
the paths end up like `/audio-books` and `/audio-books/id`.
[source](https://stackoverflow.com/questions/5334465/routes-with-dash-instead-of-underscore-in-ruby-on-rails)