From 9d818b4ec2a1d30c5f8db311fc6f7283f50083c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 2 Sep 2024 15:06:19 +0200 Subject: [PATCH] Make it easier to add custom routes Until now, people had to edit the original route files in order to add custom routes. This was inconsistent with the other customizations, since we use custom folders or files for customizing controllers, components, views, ... (which you usually customize as well when adding a new route). So now we're providing a file for custom routes, which will make it easier to know which routes are not present in Consul Democracy by default. --- config/routes.rb | 2 ++ config/routes/custom.rb | 28 ++++++++++++++++++++++++++ docs/en/SUMMARY.md | 1 + docs/en/customization/customization.md | 1 + docs/en/customization/introduction.md | 1 + docs/en/customization/routes.md | 27 +++++++++++++++++++++++++ docs/es/SUMMARY.md | 1 + docs/es/customization/customization.md | 1 + docs/es/customization/introduction.md | 1 + docs/es/customization/routes.md | 27 +++++++++++++++++++++++++ 10 files changed, 90 insertions(+) create mode 100644 config/routes/custom.rb create mode 100644 docs/en/customization/routes.md create mode 100644 docs/es/customization/routes.md diff --git a/config/routes.rb b/config/routes.rb index 3d64fe247..6359ad589 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,8 @@ Rails.application.routes.draw do mount Ckeditor::Engine => "/ckeditor" mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? + draw :custom + draw :account draw :admin draw :budget diff --git a/config/routes/custom.rb b/config/routes/custom.rb new file mode 100644 index 000000000..8c5264b50 --- /dev/null +++ b/config/routes/custom.rb @@ -0,0 +1,28 @@ +# Add your custom routes here. +# +# For example, if you'd like to add a new section in the admin area +# to manage happy thoughts and verify they've become true, you can +# write: +# +# namespace :admin do +# resources :happy_thoughts do +# member do +# put :verify +# end +# end +# end +# +# Or, if, for example, you'd like to add a form to edit debates in the +# admin area: +# +# namespace :admin do +# resources :debates, only: [:edit, :update] +# end +# +# Doing so, the existing debates routes in the admin area will be kept, +# and the routes to edit and update them will be added. +# +# Note that the routes you define on this file will take precedence +# over the default routes. So, if you define a route for `/proposals`, +# the default action for `/proposals` will not be used and the one you +# define will be used instead. diff --git a/docs/en/SUMMARY.md b/docs/en/SUMMARY.md index d1ac2ea7f..5401ff654 100644 --- a/docs/en/SUMMARY.md +++ b/docs/en/SUMMARY.md @@ -40,6 +40,7 @@ * [Other Ruby classes (GraphQL, lib, mailers, builders)](customization/ruby.md) * [Gems](customization/gems.md) * [Application configuration](customization/application.md) + * [Routes](customization/routes.md) * [Tests](customization/tests.md) * [Technical Features](features/features.md) diff --git a/docs/en/customization/customization.md b/docs/en/customization/customization.md index 208ea0284..1921e7bdb 100644 --- a/docs/en/customization/customization.md +++ b/docs/en/customization/customization.md @@ -12,4 +12,5 @@ * [Other Ruby classes (GraphQL, lib, mailers, builders)](ruby.md) * [Gems](gems.md) * [Application configuration](application.md) +* [Routes](routes.md) * [Tests](tests.md) diff --git a/docs/en/customization/introduction.md b/docs/en/customization/introduction.md index 4d04132d8..4073f91a8 100644 --- a/docs/en/customization/introduction.md +++ b/docs/en/customization/introduction.md @@ -41,6 +41,7 @@ There are also files where you can apply some customizations: * `config/environments/custom/production.rb` * `config/environments/custom/staging.rb` * `config/environments/custom/test.rb` +* `config/routes/custom.rb` * `Gemfile_custom` Using these files, you will be able to customize [translations](translations.md), [images](images.md), [CSS](css.md), [JavaScript](javascript.md), [HTML views](views.md), any Ruby code like [models](models.md), [controllers](controllers.md), [components](components.md) or [other Ruby classes](ruby.md), [gems](gems.md), [application configuration](application.md), [routes](routes.md) and [tests](tests.md). diff --git a/docs/en/customization/routes.md b/docs/en/customization/routes.md new file mode 100644 index 000000000..bbd4a3e38 --- /dev/null +++ b/docs/en/customization/routes.md @@ -0,0 +1,27 @@ +# Customizing routes + +When adding custom controller actions, you also need to define a route to configure the URL that will be used for those actions. You can do so by editing the `config/routes/custom.rb` file. + +For example, if you'd like to add a new section in the admin area to manage happy thoughts and verify they've become true, you can write: + +```ruby +namespace :admin do + resources :happy_thoughts do + member do + put :verify + end + end +end +``` + +Or, if, for example, you'd like to add a form to edit debates in the admin area: + +```ruby +namespace :admin do + resources :debates, only: [:edit, :update] +end +``` + +Doing so, the existing debates routes in the admin area will be kept, and the routes to edit and update them will be added. + +Note that the routes you define on this file will take precedence over the default routes. So, if you define a route for `/proposals`, the default action for `/proposals` will not be used and the one you define will be used instead. diff --git a/docs/es/SUMMARY.md b/docs/es/SUMMARY.md index f45c50de1..2010561df 100644 --- a/docs/es/SUMMARY.md +++ b/docs/es/SUMMARY.md @@ -40,6 +40,7 @@ * [Otras clases de Ruby (GraphQL, lib, mailers, builders)](customization/ruby.md) * [Gemas](customization/gems.md) * [Configuración de la aplicación](customization/application.md) + * [Rutas](customization/routes.md) * [Tests](customization/tests.md) * [Funcionalidades Técnicas](features/features.md) diff --git a/docs/es/customization/customization.md b/docs/es/customization/customization.md index 70372ab9b..785cfff1e 100644 --- a/docs/es/customization/customization.md +++ b/docs/es/customization/customization.md @@ -12,4 +12,5 @@ * [Otras clases de Ruby (GraphQL, lib, mailers, builders)](ruby.md) * [Gemas](gems.md) * [Configuración de la aplicación](application.md) +* [Rutas](routes.md) * [Tests](tests.md) diff --git a/docs/es/customization/introduction.md b/docs/es/customization/introduction.md index 2057946c9..f5e4292ae 100644 --- a/docs/es/customization/introduction.md +++ b/docs/es/customization/introduction.md @@ -41,6 +41,7 @@ Aparte de estos directorios, también puedes utilizar los siguientes ficheros: * `config/environments/custom/production.rb` * `config/environments/custom/staging.rb` * `config/environments/custom/test.rb` +* `config/routes/custom.rb` * `Gemfile_custom` Utilizando estos ficheros, podrás personalizar [traducciones](translations.md), [imágenes](images.md), [CSS](css.md), [JavaScript](javascript.md), [vistas HTML](views.md), cualquier código de Ruby como [modelos](models.md), [controladores](controllers.md), [componentes](components.md) u [otras clases de Ruby](ruby.md), [gemas](gems.md), [configuración de la aplicación](application.md), [rutas](routes.md) y [tests](tests.md). diff --git a/docs/es/customization/routes.md b/docs/es/customization/routes.md new file mode 100644 index 000000000..73fbc0976 --- /dev/null +++ b/docs/es/customization/routes.md @@ -0,0 +1,27 @@ +# Personalización de rutas + +Al añadir acciones de controlador personalizadas, necesitas definir una ruta que configure la URL que se usará para esas acciones. Puedes hacerlo editando el fichero `config/routes/custom.rb`. + +Por ejemplo, para añadir una nueva sección al área de administración para gestionar pensamientos felices ("happy thoughts", en inglés) y verificar que se han hecho realidad, puedes escribir el siguiente código: + +```ruby +namespace :admin do + resources :happy_thoughts do + member do + put :verify + end + end +end +``` + +O, si, por ejemplo, quisieras añadir un formulario para editar debates en el área de administración: + +```ruby +namespace :admin do + resources :debates, only: [:edit, :update] +end +``` + +Al hacer esto, las rutas existentes de debates en el área de administración se mantendrán, y a ellas se añadirán las rutas "edit" y "update". + +Las rutas que defines en este fichero tendrán precedencia sobre las rutas por defecto. Así que, si defines una ruta para `/proposals`, la acción por defecto para `/proposals` no se utilizará sino que en su lugar se usará la que definas tú.