From bd41a371b12c7b90af8b422dc348a45aab7607e4 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 18 Nov 2019 09:40:40 -0600 Subject: [PATCH] Add Customize The Path Of A Resource Route as a rails til --- README.md | 3 ++- .../customize-the-path-of-a-resource-route.md | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 rails/customize-the-path-of-a-resource-route.md diff --git a/README.md b/README.md index 40c69ee..ace0d83 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_868 TILs and counting..._ +_869 TILs and counting..._ --- @@ -513,6 +513,7 @@ _868 TILs and counting..._ - [Convert A Symbol To A Constant](rails/convert-a-symbol-to-a-constant.md) - [Creating Records of Has_One Associations](rails/creating-records-of-has-one-associations.md) - [Custom Validation Message](rails/custom-validation-message.md) +- [Customize The Path Of A Resource Route](rails/customize-the-path-of-a-resource-route.md) - [Delete Paranoid Records](rails/delete-paranoid-records.md) - [Demodulize A Class Name](rails/demodulize-a-class-name.md) - [Disambiguate Where In A Joined Relation](rails/disambiguate-where-in-a-joined-relation.md) diff --git a/rails/customize-the-path-of-a-resource-route.md b/rails/customize-the-path-of-a-resource-route.md new file mode 100644 index 0000000..0d80904 --- /dev/null +++ b/rails/customize-the-path-of-a-resource-route.md @@ -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)