-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Namespaced resource route generates incorrect aliases #26
Comments
Actually, the above convention doesn't exist in rails and actually raises an error. Given this we can:
Would like to hear everyones thought's on this one. I believe @darkofabijan has previously suggested a scope option such as |
We could use the following: defmodule Router do
use Phoenix.Router, port: 4000
scope "admin" do
resources "users", Phoenix.Controllers.Users do
resources "comments", Phoenix.Controllers.Comments
end
end
end Rails has this same syntax so it should feel the same. I don't mind having the option to inline |
Also, the defmodule Router do
use Phoenix.Router, port: 4000
scope "/admin/hidden" do
resources "users", Phoenix.Controllers.Users do
resources "comments", Phoenix.Controllers.Comments
end
end
end |
@nurugger07 I would prefer that style too. In that case we could also Thinking that it's more important that routing DSL is clean and pleasant to use over being simple to maintain is valid I think. The question is just how should we approach development of this or any other component. There is a perfect solution for router, there is one good enough for now and there is one that can be done in two hours. In the end purpose of these discussion is to find middle ground. I just felt it would be easier for me to explain my proposition by open-sourcing my thinking process. :) |
@darkofabijan I go back and forth on how closely to build things in a similar manner to Rails. There are pros and cons, but it is a DSL people are familiar with. I do prefer I think the discussion is good as well :) |
@darkofabijan Go ahead on this one. Here's my thoughts on the proposed approaches. Feel free to try both out and see what feels right Mapper wise. My vote is for 1 since it accommodates most use-cases, but we have to implement it cleanly.
resources "user", Users, scope: "private/admin" do
...
end This approach doesn't not require additional macros, but will still involve Router.Context, perhaps to a lesser degree of refactoring. What this approach lacks is the ability to scope entire sections of non resource based router. So if you wanted to scope a series of gets/posts/puts, you'd have to repeat the scope, which is undesirable. |
I don't like scope path: "private/admin" do
...
end scope alias: Admin do
...
end I liked namespace in Rails 2 router because it meant scoping many things at once: the path, the alias and the named helpers. |
I like the idea of providing both a path and alias option as it combines a few active issues we've been discussing. Because we require explicit controllers right now, |
+1 on @josevalim's proposal. I like the idea of being explicit with the intent. |
@josevalim 👍 I agree about Rails router comments. That's what would people expect from scoping, and is probably the one that makes most sense. But it's the same in Rails 3 isn't it? https://gist.github.com/darkofabijan/8833685 path, controller and helpers are scoped. I am not sure what would I gain by just scoping path or alias? In any of the Rails routing files that I am checking namespaces are used to scope all three, and it's good. Ok since we specify controller explicitly so that would not be an issue, but named helpers would be. E.g. resources "users", Controllers.Users
scope path: "/admin", alias: Controllers.Admin do
resources "users", Users
end In the example above we would be still stuck with same named helpers. And since we are explicitly specifying controllers we should probably also explicitly specify helpers scoping. scope path: "/admin", alias: Controllers.Admin, helper: "admin" do
resources "users", Users
end Do you guys see anything wrong with last example? As @josevalim stated it is really desired behaviour. Since we are not using implicit DSL I guess that being explicit about everything is I guess the price we have pay. :) It gives user much freedom, maybe unneeded. P.S. I think I might have secret desire for implicit DSL :D |
Good point about not knowing what to make the named route helper functions. I agree |
I think I'm agreeing with @darkofabijan that the arguments should act more like overrides. If I define a named scope, it's easy to assume a convention that names path. alias, helper, and controller. In the adverse, if all the names match up, I don't want to have to explicitly name them. |
Once we have all the functionality in place for routing, I plan to open a RFC on convention over configuration. My main focus at the moment is two fold:
Things are progressing very nicely with the router and we should be able to start playing with apps and seeing what feels right as far as conventions go, keeping 1 & 2 above in mind. |
+1 @chrismccord I totally agree. It's best to have a solid routing tool first. The only argument I would have for implied behavior in this situation is to reduce redundancy in defining scopes. |
I agree on all points and I am especially happy about the following:
There is nothing better than using, even early prototype, in the wild. It makes things clear without much thinking, sets the roadmap and is also great motivator. |
@darkofabijan's PR has been merged and I'm very happy with the results. There is some redundancy of |
Maybe you could support |
@josevalim I like the symmetry that you are suggesting. In resources example |
…ction-to-controller-guide add redirection to controller guide, including redirect/2 and redirect/3
mix phoenix.routes Router
We need to detect these scenarios and convert to underscores
The text was updated successfully, but these errors were encountered: