-
-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inferred defaults for routes #1297
Comments
I don't think it should. You may want to use whatever object as the handler. Setting the namespace implicitly would make it impossible. What I would suggest instead would be setting |
Actually, yes, that would be a nice quality of life improvement. Expanding upon this, it would be nice to take this boilerplate code: slice :api, at: "/api" do
get "/tasks", to: "tasks.index", as: :tasks
get "/tasks/:id", to: "tasks.show", as: :task
get "/tasks/new", to: "tasks.new", as: :task_new
get "/tasks/:id/edit", to: "tasks.edit", as: :task_edit
post "/tasks", to: "tasks.create", as: :task_create
patch "/tasks/:id", to: "tasks.patch", as: :task_patch
put "/tasks/:id", to: "tasks.update", as: :task_update
delete "/tasks/:id", to: "tasks.delete", as: :task_delete
scope :chat do
post "/slack", to: "chat.slack.create", as: :slack_create
end
end ...and turn it into this: slice :api do
get "/tasks"
get "/tasks/:id"
get "/tasks/new"
get "/tasks/:id/edit"
post "/tasks"
patch "/tasks/:id"
put "/tasks/:id"
delete "/tasks/:id"
scope :chat do
post "/slack"
end
end The last code snippet would be identical in behavior to the first snippet but without all of the typing! You could then override the inferred defaults -- per your suggestion -- by customizing Happy to rewrite this issue to reflect the above if you think this would be a welcomed change? |
Peter: I opted to rename and reword this issue based on our discussion since the resolution would have more impact to the community at large. |
Hi! I'm just introducing myself to Hanami and would like to try my hand at this issue! |
Overview
Hello. 馃憢 I'm finding there is a lot of boilerplate code necessary to build routes especially if you want them named by default so you can leverage named routes like the following:
routes.path :api_tasks
routes.url :api_tasks
I'd like to propose that, when building routes, only the minimum syntax is necessary which infers safe defaults while still allowing complete flexibility to customize as necessary.
Steps to Recreate
Consider the following:
The above requires a lot of typing for little gain. Especially, since all of the above could be inferred from that path. Instead, I'd like to suggest that you be able to write the above as follows:
The last code snippet is identical in behavior to the first snippet but without all of the typing! This can be done by translating the given block context plus the route path into the necessary keys. Here's a few examples:
"tasks.index"
, Named Route::tasks
"tasks.show"
, Names Route::task
"chat.slack.create"
, Names Route::slack_create
At any time you could override the inferred defaults by customizing
:at
,:to
, and:as
as you see fit but if you just wanted to roll with the inferred defaults you'd save yourself a lot of time.Environment
Notes
This issue came about from the discussion between Peter and me below so I've rephrased this issue to have a bit more impact.
The text was updated successfully, but these errors were encountered: