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.
This commit is contained in:
Javi Martín
2024-09-02 15:06:19 +02:00
parent ee089a5209
commit 9d818b4ec2
10 changed files with 90 additions and 0 deletions

View File

@@ -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

28
config/routes/custom.rb Normal file
View File

@@ -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.

View File

@@ -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)

View File

@@ -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)

View File

@@ -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).

View File

@@ -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.

View File

@@ -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)

View File

@@ -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)

View File

@@ -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).

View File

@@ -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ú.