From 7db96bc237ef7c1230ec7a8a6cb94b798c552a46 Mon Sep 17 00:00:00 2001 From: moznion Date: Thu, 22 Aug 2024 23:31:50 +0900 Subject: [PATCH 1/2] Add a style guide to suggest to pass a string literal as a URL to http method calls Original discussion: https://github.com/rubocop/rails-style-guide/issues/328 Signed-off-by: moznion --- README.adoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.adoc b/README.adoc index 47652a5..432e995 100644 --- a/README.adoc +++ b/README.adoc @@ -231,6 +231,23 @@ match ':controller(/:action(/:id(.:format)))' Don't use `match` to define any routes unless there is need to map multiple request types among `[:get, :post, :patch, :put, :delete]` to a single action using `:via` option. +=== HTTP URL [[http-url]] + +Prefer passing a string literal as a URL to HTTP methods to make the actual URL obvious and to facilitate tracking endpoint path changes. + +[source,ruby] +---- +# bad +get photos_path +put photo_path(id) +post edit_photo_path(id) + +# good +get "/photos" +put "/photos/#{id}" +post "/photos/#{id}/edit" +---- + == Controllers === Skinny Controllers [[skinny-controllers]] From 1c4cf0e5aae086e1e87a1746385828f38a2154f2 Mon Sep 17 00:00:00 2001 From: moznion Date: Fri, 23 Aug 2024 11:49:52 +0900 Subject: [PATCH 2/2] Move "http-url" rule to under the "Testing" section Signed-off-by: moznion --- README.adoc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/README.adoc b/README.adoc index 432e995..590cba1 100644 --- a/README.adoc +++ b/README.adoc @@ -231,23 +231,6 @@ match ':controller(/:action(/:id(.:format)))' Don't use `match` to define any routes unless there is need to map multiple request types among `[:get, :post, :patch, :put, :delete]` to a single action using `:via` option. -=== HTTP URL [[http-url]] - -Prefer passing a string literal as a URL to HTTP methods to make the actual URL obvious and to facilitate tracking endpoint path changes. - -[source,ruby] ----- -# bad -get photos_path -put photo_path(id) -post edit_photo_path(id) - -# good -get "/photos" -put "/photos/#{id}" -post "/photos/#{id}/edit" ----- - == Controllers === Skinny Controllers [[skinny-controllers]] @@ -1938,6 +1921,23 @@ travel_to(Time.current.to_time) freeze_time ---- +=== HTTP URL [[http-url]] + +Prefer passing a string literal as a URL to HTTP methods to make the actual URL obvious and to facilitate tracking endpoint path changes. + +[source,ruby] +---- +# bad +get photos_path +put photo_path(id) +post edit_photo_path(id) + +# good +get "/photos" +put "/photos/#{id}" +post "/photos/#{id}/edit" +---- + == Managing Processes === Foreman [[foreman]]