Skip to content

Commit

Permalink
Add a style guide to suggest to pass a string literal as a URL to htt…
Browse files Browse the repository at this point in the history
…p method calls

Original discussion: rubocop#328

Signed-off-by: moznion <[email protected]>
  • Loading branch information
moznion committed Aug 22, 2024
1 parent 524a1ac commit 7db96bc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down

0 comments on commit 7db96bc

Please sign in to comment.